Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 995
Fabian Barkhau Avatar asked Nov 18 '15 23:11

Fabian Barkhau


2 Answers

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.

like image 167
viraptor Avatar answered Nov 10 '22 18:11

viraptor


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.

like image 2
Fabian Barkhau Avatar answered Nov 10 '22 19:11

Fabian Barkhau