- Documentation
- Reference manual
- Packages
- SWI-Prolog Python interface
- library(janus): Call Python from Prolog
- py_version/0
- py_call/1
- py_call/2
- py_call/3
- py_iter/2
- py_iter/3
- py_is_object/1
- py_free/1
- py_with_gil/1
- py_func/3
- py_func/4
- py_dot/4
- py_dot/5
- values/3
- keys/2
- key/2
- items/2
- py_shell/0
- py_pp/1
- py_pp/2
- py_pp/3
- py_obj_dir/2
- py_obj_dict/2
- py_initialize/3
- py_lib_dirs/1
- py_add_lib_dir/1
- py_add_lib_dir/2
- Handling Python errors in Prolog
- Janus and virtual environments (venv)
- library(janus): Call Python from Prolog
- SWI-Prolog Python interface
4.2 Janus and virtual environments (venv)
An embedded Python system does not automatically pick up Python
virtual environments. It is supposed to setup its own environment. Janus
is sensitive to Python venv environments. Running under such as
environment is assumed if the environment variable
VIRTUAL_ENV points at a directory that holds a file
pyvenv.cfg. If the virtual environment is detected, the
actions in the list below are taken.1This
is based on observing how Python 3.10 on Linux responds to being used
inside a virtual environment. We do not know whether this covers all
platforms and versions.
- Initialize Python using the
-Iflag to indicate isolation. - Set
sys.prefixto the value of theVIRTUAL_ENVenvironment variable. - Remove all directories with base name
site-packagesordist-packagesfromsys.path.2Note that-Ionly removes the personal packages directory, while the Python executable removes all, so we do the same. - Add
$VIRTUAL_ENV/lib/pythonX.Y/site-packagestosys.path, where X and Y are the major and minor version numbers of the embedded Python library. If this directory does not exist we print a diagnostic warning. - Add a message to py_version/0 that indicates we are using a virtual environment and from which directory.