venv and executing other python programs

Eryk Sun eryksun at gmail.com
Tue Feb 15 23:16:24 EST 2022


On 2/15/22, Martin Di Paola <martinp.dipaola at gmail.com> wrote:
>
> That's correct. I tried to be systematic in the analysis so I tested all
> the possibilities.

Your test results were unexpected for `python3 -m venv xxx`. By
default, virtual environments exclude the system and user site
packages. Including them should require the command-line argument
`--system-site-packages`. I'd check sys.path in the environment. Maybe
you have PYTHONPATH set.

> I had to test this myself because I didn't believe it but you are right.
> Without having the venv activated, if the shebang explicitly points to
> the python executable of the venv, the program will have access to the
> libs installed in the environment.

A virtual environment is configured by a "pyvenv.cfg" file that's
either beside the executable or one directory up. Activating an
environment is a convenience, not a requirement.


More information about the Python-list mailing list