Vinay Sajip added the comment:

When using an activated virtual environment, there is no need to use "py" - 
just use "python". Primarily, the launcher looks for a shebang line in a script 
to determine which interpreter to use for the script. If no shebang line can be 
found, it will launch "the default" Python, which is currently the most recent 
Python 2.x found in the registry. When invoked via py -3 (or with suitable 
settings in the configuration), it will use the most recent Python 3.x found in 
the registry. Since venv interpreters are not in the registry, they will never 
be invoked as the default Python. However, any scripts installed into venvs 
will have the correct shebang lines, so they will launch with the venv's 
interpreter.

I don't believe this is a bug, as the system is IMO working as designed and as 
per PEP 397. If the launcher is asked to launch a script which contains a 
shebang, while a venv is activated, it will run with the interpreter indicated 
by the shebang, rather than the venv's interpreter.

Perhaps one could consider an enhancement whereby if no shebang is found, a 
different approach is used to find the interpreter - e.g. looking for "python" 
on the path before looking in the registry to locate an interpreter. The 
question arises as to whether this should be tied to a specific condition such 
as the presence of an environment key PYLAUNCHER_USEPATH. (This is of course 
orthogonal to whether or not a venv is activated, but would have the desired 
effect when a venv is activated, without needing to tie the launcher to a 
virtualenv-specific environment value such as VIRTUAL_ENV.)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17010>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to