Description
- Pip version: any (tested with 9.0.1)
- Python version: any (tested with 3.6.1)
- Operating system: any (tested on MS-Win)
Question / Improvement?
When using pip under MS-Win, the shebang of the console scripts is always a absolute pathname. So far I can see, for shebang pip uses the value from:
import sys
sys.executable
Since this is always an absolute pathname, those console '.exe' scripts will not work in different (virtual) environments or in portable python setups. In POSIX like environments, it is very common to use a shebang with an env call:
#!/usr/bin/env python
Since there is no 'env' tool on windows, I expect a simple shebang wich does nearly the same, using first python interpreter from PATH:
#!python
My question is, why do we use absolute pathnames in shebang instead of using the first python from the PATH env?
What I've run (my workaround):
I wrote a small hackish pip.bat
wrapper around my pip
python -c "import pip, sys;sys.executable='python.exe';pip.main()" %*
which replaces the absolute pathname with sys.executable='python.exe'
. So I get portable console scripts with the #!python
shebang.
But the question remains, why is it better to use absolute pathnames? I guess this is the same on POSIX systems, where pip also uses absolute pathnames instead of using /usr/bin/env
.
Thanks!
Update 10/2018
See #4616 (comment) from @amr66, newer versions (18.1) of pip have moved the main function to pip._internal
and you need:
python -c "from pip._internal import main, sys;sys.executable='python.exe';main()" %*