[issue34359] Wrong virtual environment found

Paul Moore report at bugs.python.org
Wed Aug 8 10:40:36 EDT 2018


Paul Moore <p.f.moore at gmail.com> added the comment:

>From https://docs.python.org/3.7/using/windows.html#shebang-lines the supported shebang lines are

* /usr/bin/env python
* /usr/bin/python
* /usr/local/bin/python
* python

There's a provision in there:

"""
The /usr/bin/env form of shebang line has one further special property. Before looking for installed Python interpreters, this form will search the executable PATH for a Python executable. This corresponds to the behaviour of the Unix env program, which performs a PATH search.
"""

The launcher does *not* implement the full functionality of the Unix "env" program, and in particular doesn't support (relative or absolute) paths in the Python interpreter part.

While "search PATH for the relative path given in the env shebang line" would be a potential feature request, it's not current behaviour, and in my view, it's too rare of a scenario to be worth the complexity it would add to the launcher.

As a workaround, you can use an absolute path in your shebang line:

#!F:\python\scripts3\.venv\Scripts\python.exe

(Obviously that requires a little more manual management of the shebang lines in your scripts).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34359>
_______________________________________


More information about the Python-bugs-list mailing list