0

If I have a python package that contains an executable script and setup.py mentions it in its scripts field, it gets installed into the bin directory.

When it does that, however, it rewrites any #! line in that script to point to the path of the python being used. I would like to specify my own #! line.

When I was using setup.py on its own, I had a workaround. The build command has an --executable option that does exactly what I need. Unfortunately, the install command doesn't recognize it, but I could break the install into two steps:

python3 setup.py build --executable=...
python3 setup.py install --skip-build

Is there a way to do the equivalent of --executable with pip?

The intention is to have executable scripts begin with '#!/usr/bin/env python3', which will invoke python from the path. I realize that this is not a good idea in most cases, but I'm installing an environment (which contains more than just python) that needs to function no matter where it exists in the file system (i.e., you can mount it somewhere else, and it still works), so I don't want any absolute paths except for things like /usr/bin/env which are always going to be present. The system already works, but I'm trying to move my python package installation from raw setup.py to pip and ran into this snag.

4
  • 2
    Why not just set up the virtualenv with the path of the Python being used, and then install the package normally? Commented Mar 2, 2023 at 6:37
  • 1
    BTW, the "#! line" is commonly called a shebang. Commented Mar 2, 2023 at 6:38
  • Note that there are good reasons for pip not to do this by default, because the dependencies of your script are only getting installed for the one interpreter pip is installing your script for; on any other it may not run on account of libraries it depends on not being present. This is of course moot if your script is sufficiently self-contained, but pip's purpose is to deal with things that have dependency trees. Commented Mar 2, 2023 at 16:50
  • I agree that pip's default is good - I'd just like to override it for a particular situation. I will keep the same interpreter so there shouldn't be a problem with libraries not being present at runtime. It's just that the path to that interpreter may not be known at module-installation time because the whole environment might wind up being mounted somewhere else. Commented Mar 2, 2023 at 17:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.