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!

astrofrog
  • 32,883
  • 32
  • 90
  • 131
  • 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`. – astrofrog Dec 23 '10 at 10:41
  • possible duplicate of [Don't touch my shebang!](http://stackoverflow.com/questions/1530702/dont-touch-my-shebang) – Lennart Regebro Dec 23 '10 at 10:52

1 Answers1

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.

gruszczy
  • 40,948
  • 31
  • 128
  • 181