link to venv python sees a different sys.path

Dieter Maurer dieter at handshake.de
Wed Mar 11 13:24:31 EDT 2020


Robin Becker wrote at 2020-3-11 15:26 +0000:
>I'm trying to understand why python 3.8.2 venv behaves differently when it is executed va a link
>
>Make the env
>> rptlab at everest:~/code/hg-repos
>> $ python38 -mvenv __py__/382v
>> rptlab at everest:~/code/hg-repos
>
>make a link
>> $ ln -s ../__py__/382v/bin/python bin/python382v
>
>the venv sys.path
>> rptlab at everest:~/code/hg-repos > $ __py__/382v/bin/python -c"import sys;print('\n'.join(sys.path))"
>>
>> /home/rptlab/LOCAL/382/lib/python38.zip
>> /home/rptlab/LOCAL/382/lib/python3.8
>> /home/rptlab/LOCAL/382/lib/python3.8/lib-dynload
>> /home/rptlab/code/hg-repos/__py__/382v/lib/python3.8/site-packages
>> rptlab at everest:~/code/hg-repos
>
>the linked python sys.path
>> $ bin/python382v -c"import sys;print('\n'.join(sys.path))"
>>
>> /home/rptlab/LOCAL/382/lib/python38.zip
>> /home/rptlab/LOCAL/382/lib/python3.8
>> /home/rptlab/LOCAL/382/lib/python3.8/lib-dynload
>> /home/rptlab/LOCAL/382/lib/python3.8/site-packages
>> rptlab at everest:~/code/hg-repos
>> $
>
>so the linked version of the venv python sees the base python site packages and not the expected venv site-packages.

I guess (!) that it is using the path to the interpreter program
in order to locate the venv's "site-packages" and falls back to
the system's when this is not possible.

If my guess is correct, then some links will not work.
But, you should be able to use links which find
"site-packages" via "<interpreter path>/../lib/python<version>/site-packages".


More information about the Python-list mailing list