venv and executing other python programs

Martin Di Paola martinp.dipaola at gmail.com
Tue Feb 15 21:18:58 EST 2022


>If you have activated the venv then any script that uses /usr/bin/env 
>will use executables from the venv
>bin folder.

That's correct. I tried to be systematic in the analysis so I tested all 
the possibilities.

>I avoid all these issues by not activating the venv. Python has code to 
>know
>how to use the venv libraries that are installed in it when invoked. It does not
>depend on the activate script being run.

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.

The same if I do:

/home/user/venv/bin/python foo.py

Thanks for the info!
>
>Barry
>
>
>>
>> Do you have a particular context where you are having troubles? May be there is something else going on...
>>
>> Thanks,
>> Martin.
>>
>> On Tue, Feb 15, 2022 at 06:35:18AM +0100, Mirko via Python-list wrote:
>>> Hi,
>>>
>>> I have recently started using venv for my hobby-programming. There
>>> is an annoying problem. Since venv modifies $PATH, python programs
>>> that use the "#!/usr/bin/env python" variant of the hashbang often
>>> fail since their additional modules aren't install inside in venv.
>>>
>>> How to people here deal with that?
>>>
>>> Please note: I'm not interested in discussing whether the
>>> env-variant is good or bad. ;-) It's not that *I* use it, but
>>> several progs in /usr/bin/.
>>>
>>> Thanks for your time.
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>


More information about the Python-list mailing list