How to prevent the spread of a python wheel from shebang?

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

This is obviously a problem, since anyone who uses the wheel will not have this setting. It doesn't seem to matter what type of shebang I am using.

+5
source share
3 answers

I finally narrowed it down and found a problem.

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

  • Use a valid shebang in the script that is added to setup.py. In my case #!/usr/bin/env python

  • Create virtualenv using virtualenv -p /usr/bin/python2 env and activate using source env/bin/activate .

  • Install the package with python setup.py install in virtualenv.

  • Create a wheel using python setup.py bdist_wheel .

The problem is installing the package on virtualenv in step 3. If this is not done, shebang does not expand.

+2
source

This usually should not happen. I would suggest either:

  • Updating pip / wheel / setuptools settings and checking, maybe this is a mistake.

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

Here I can not reproduce the problem:

 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 unzip this wheel, s.py will have an invalid / placeholder shbang #!python , but during the actual installation it will be changed to the correct system / virtualenv path.

+2
source

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

Edit: This is not the case!

0
source

Source: https://habr.com/ru/post/1236274/


All Articles