1

I apologize since I'm somewhat new to Python. I would like to install a (setuptools-based) package, but when the scripts are installed, I would like to change the #! line.

I've found documentation that says to use -e/--executable for this purpose, but that is not a recognized option to python3 setup.py install. If I use it with the build or build_scripts commands, it works fine, but that doesn't help me install it.

When running the install command, I see it say running build_scripts and even though I have executable defined in setup.cfg for build_scripts, it only seems to have any effect when I call build_scripts explicitly, not when it's called from install.

I've found very little documentation about what setuptools commands do - plenty of basic tutorials and several references about the various arguments to set up, but nothing about what the commands actually do or how to configure them. Any pointers would be much appreciated!

Thanks!

Edit: I did some more experiments and found that although build/build_scripts did what it was told regarding the --executable switch, the install command created an egg, and the egg-creation process rewrote the shebang line. If I use:

python3 setup.py build --executable='/usr/bin/env python3'
python3 setup.py install --skip-build --prefix=xxx --single-version-externally-managed --root=/

it works. I need to do this in two steps because --executable isn't recognized by install (though it does work with just the install if I put it in setup.cfg for build). Is this the right way to do this? It sounds like a lot of hackery for something very simple. I can't really find any documentation on what --single-version-externally-managed does. It seems to suppress egg generation, and that was causing the problem, but I don't know if that has any other effects to be aware of.

user1806566
  • 1,078
  • 6
  • 18
  • What do you mean you would like the to change the shebang line? What shebang are you currently using? What is the path to your python3.7? What platform are you on? – Elliott Frisch Jan 15 '19 at 17:12
  • I'm on Linux. The installer changes the shebang line to be the python that was used to do the install. I'd like to change it to #!/usr/bin/env python3. – user1806566 Jan 15 '19 at 18:23
  • AFAIK `setuptools` will always quote shebangs with whitespaces, see [open issue #494](https://github.com/pypa/setuptools/issues/494). The only workaround I know is using `distutils` which handles the shebangs with spaces quite well - but again, if you need to support windows, think `C:\Program Files\ ` and friends. Also, a downgrade from `setuptools` from `distutils` is rarely possible per se. – hoefling Jan 15 '19 at 23:22
  • Also, check out the answer here: [Override the shebang mangling in python setuptools](https://stackoverflow.com/q/37874445/2650249). Didn't try it myself though. – hoefling Jan 15 '19 at 23:26
  • Thanks for the responses! It looks like the --executable option to build works as advertised, though it's frustrating that you can't specify it to the install command. The problem seems to be that setuptools by default wants to install an egg, and the egg-creation step has a mind of its own: it trashes the setting of executable, and it fusses about things it has no business fussing about (environment variables, the install directory not existing, etc.). It seems the egg exists to solve problems I don't have, so if --single-version-externally-managed skips the egg, that works for me. – user1806566 Jan 16 '19 at 17:02

0 Answers0