2

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!

2
  • 1
    It turned out that if I removed the build directory and tried again, it changed the path to the correct one, but I'd still be interested to know whether it's possible to keep the original #!/usr/bin/env python. Commented Dec 23, 2010 at 10:41
  • possible duplicate of Don't touch my shebang! Commented Dec 23, 2010 at 10:52

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.