Search code examples
pythonshebangpython-wheel

How to prevent python wheel from expanding shebang?


If I build a package with python setup.py bdist_wheel, the resulting package expands the shebangs in the scripts listed in setup.py via setup(scripts=["script/path"]) to use the absolute path to my python executable #!/home/f483/dev/storj/storjnode/env/bin/python.

This is obviously a problem as anyone using the wheel will not have that setup. It does not seem to make a difference what kind of shebang I am using.


Solution

  • I finally narrowed it down and found the problem.

    Here the exact steps to reproduce the problem and the solution.

    1. Use a valid shebang in a script thats added in setup.py. In my case #!/usr/bin/env python

    2. Create a virtualenv with virtualenv -p /usr/bin/python2 env and activate with source env/bin/activate.

    3. Install the package with python setup.py install to the virtualenv.

    4. Build the wheel with python setup.py bdist_wheel.

    The problem is installing the package to the virtualenv in step 3. If this is not done the shebang is not expanded.