$ python -c "import sys; print('in venv') if sys.prefix != sys.base_prefix else print('not in venv')"
not in venv
$ . venv/bin/activate
(venv)
$ python -c "import sys; print('in venv') if sys.prefix != sys.base_prefix else print('not in venv')"
in venv
(venv)
$ swipl
2 ?- py_shell .
Python 3.11.5 (main, Sep 2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import sys; print('in venv') if sys.prefix != sys.base_prefix else print('not in venv')
not in venv
>>>
I see. I was building the Janus interface as Python package in the venv. That works fine. Here the problem is that the embedded Python does not listen to to the virtualenv. Does anyone know how to handle this? The virtualenv seems to make two changes to the environment:
set VIRTUAL_ENV
modify PATH to add $VIRTUAL_ENV/bin
I found quite a couple of suggestions on how to handle this, but mostly contradicting, not working, etc.
Avoid preset site-packages. Docs says this is done using -I, but this only part of the story: using Python inside a venv also removes the system wide local packages and -I does not; it only removes the user one. It seems venv removes all directories with site-packages and dist-packages
Add the site-packages from $VIRTUAL_ENV. Only, this is (for me) in $VIRTUAL_ENV/lib/python3.10/site-packages. Form where do I get the 3.10? Is this always the major.minor version?
. venv/bin/activate
swipl
?- py_version.
% Janus embeds Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
% Janus: using venv from '/home/janw/venv'
true.
Updates sys.prefix and sys.path as described above. Works using Python 3.10 on Linux. No clue whether there is something OS/Python version specific. Not unlikely, so please report problems.