6

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Fabian Barkhau
  • 1,349
  • 2
  • 12
  • 31
  • Is this actually in the wheel? I mean, can you see your absolute path when you unpack it? I'd expect the path substitution to happen only after installation and then it just depends on your virtualenv setup. – viraptor Nov 18 '15 at 23:54
  • Yes, thats why I get an error on another machine. – Fabian Barkhau Nov 18 '15 at 23:57
  • It looks like this is a bug in wheel, there's an open ticket here: https://bitbucket.org/pypa/wheel/issues/135/bad-interpreter-lines-can-sneak-into – nnyby Apr 07 '16 at 04:22

3 Answers3

2

This should not normally happen. I'd suggest either:

  1. Upgrading pip / wheel / setuptools and checking if it was maybe a bug.

  2. Rechecking that the current shbang is something generic in the script. For example #!/usr/bin/env python

Here's a way I can't reproduce the issue:

paster --no-interactive test
mkdir test/scripts
echo -e "#!/usr/bin/env python\nprint('test')" > test/scripts/s.py
# add scripts/s.py to test/setup.py
cd test; python setup.py bdist_wheel

If you unpack that wheel, s.py will have an invalid/placeholder shbang #!python, but during actual installation, it will be changed to the proper system/virtualenv path.

viraptor
  • 33,322
  • 10
  • 107
  • 191
2

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.

Fabian Barkhau
  • 1,349
  • 2
  • 12
  • 31
0

Using the generic shebang #!python seems to solve this problem.

Edit: This is incorect!

Fabian Barkhau
  • 1,349
  • 2
  • 12
  • 31
  • 1
    It's also incorrect. If you run a file with shbang `#!python` it will just tell you it's a bad interpreter. – viraptor Nov 19 '15 at 00:00
  • The optional installation step in the wheel spec is supposed to replace `#!python` with a valid path (https://www.python.org/dev/peps/pep-0427/#recommended-installer-features). When I put `#!python` at the top of my script, wheel correctly leaves it alone when running bdist_wheel. – nnyby Apr 07 '16 at 04:07