python setup.py install changes script interpreter

馋奶兔 提交于 2020-01-04 07:46:11

问题


I have a Python package that includes a few scripts in a scripts/ folder. My setup.py file includes::

#!/usr/bin/env python

from distutils.core import setup

scripts = ['script1', 'script2', 'script3']

setup(name='Test',
      version='0.1.0',
      packages=['test'],
      scripts=['scripts/' + x for x in scripts]
     )

Each script contains the line::

#!/usr/bin/env python

at the top. However, when I run python setup.py install this line gets changed to::

#!/usr/bin/python

automatically in the installed scripts. Is there a way to avoid this? The reason that this is a problem for me is because I am using virtualenv, and so the correct path for the Python executable should be::

#/Users/user/.virtualenvs/default/bin/python

so I'd rather it left the interpreter set to::

#!/usr/bin/env python

Thanks for any advice!


回答1:


The install scripts checks, where the python is installed and changes this python to the proper one. It does it on every machine, where your package is installed.

From docs:

Scripts are files containing Python source code, intended to be started from the command line. Scripts don’t require Distutils to do anything very complicated. The only clever feature is that if the first line of the script starts with #! and contains the word “python”, the Distutils will adjust the first line to refer to the current interpreter location. By default, it is replaced with the current interpreter location. The --executable (or -e) option will allow the interpreter path to be explicitly overridden.



来源:https://stackoverflow.com/questions/4517934/python-setup-py-install-changes-script-interpreter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!