Several widely used Python tools — such as pip
, yolk
and ipython
— are launched by scripts with a shebang specifying what Python instance should be used to run them. How is the contents of this line determined?
For example, on OS X machine, where I have been using Apple's Python, this line reads
#!/usr/bin/python
What would happen if I installed the python.org version, which is placed in
/Library/Frameworks/Python.framework/Versions/2.7/python
with a symlink at
/usr/local/bin/python
and then updated or re-installed a tool? If I updated a tool would the line change? Would I have to fully reinstall (rather than simply updating) each tool to force a change? What would the line change to? Would it be
#!/usr/local/bin
or
#!/Library/Frameworks/Python.framework/Versions/2.7
Is there a way to make it
#!/usr/bin/env python
The line comes from the sys.executable
value .
If you symlink the python executable, and run Python from that symlink, sys.executable
would use the new path. Updating or reinstalling the tool would reflect the changed executable path, yes.
I am not aware of any method to make pip
and friends use #!/usr/bin/env python
instead. That'd be a bad idea, really, as that would make it harder to use the correct Python all the time, the one where the installed packages can be found needed to run the command-line script.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.