Title: Make it easier to use a venv with an embedded Python interpreter
Type: enhancement Stage:
Components: Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dieter Weber
Priority: normal Keywords:

Created on 2019-01-10 14:04 by Dieter Weber, last changed 2019-01-10 14:12 by Dieter Weber.

File name Uploaded Description Edit
Source.cpp Dieter Weber, 2019-01-10 14:10
Messages (1)
msg333378 - (view) Author: Dieter Weber (Dieter Weber) Date: 2019-01-10 14:04
Python virtual environments are awesome! Using venvs with an embedded Python interpreter has proven difficult, unfortunately. With conda environments it works. See appended a sample file to reproduce the behavior.

The core of the problem seems to be that a venv doesn't contain a full Python installation, and Py_Initialize() apparently doesn't support setting up the combination of venv directories and base installation correctly, i.e. setting sys.prefix and sys.base_prefix and potentially other values.

Observed behavior when trying to use a venv:

Initializing... Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00001e90 (most recent call first):

Expected behavior:
Setting Py_SetPythonHome() to a venv works and sets up all paths and prefixes correctly to use the venv, just like it does for a conda environment.
Date User Action Args
2019-01-10 14:12:27Dieter Webersettitle: Making an embedded Python interpreter use a venv is difficult -> Make it easier to use a venv with an embedded Python interpreter
2019-01-10 14:10:13Dieter Webersetfiles: - Source.cpp
2019-01-10 14:10:02Dieter Webersetfiles: + Source.cpp
2019-01-10 14:04:59Dieter Webercreate