Hacker News new | ask | show | jobs
by Someone 733 days ago
> but then you have to add a shebang line directly to the script itself, which I always feel uncomfortable since it's hard-coded

It won’t directly help reach your goal, but it is semi hard-coded. The ‘correct’ (but see https://unix.stackexchange.com/a/29620 for some caveats) way to write a shebang line is

  #!/usr/bin/env python
That will make it run the first python in your path.

> what if in future I don't want to execute my .py script with `/usr/bin/python` but `/usr/bin/nohtyp`?).

You could create a symlink called python to /usr/bin/nohtyp on your system in a directory that’s searched before /usr/bin (e.g. by adding ~/myCommandPreferences to the front of your PATH)

1 comments

To be excruciatingly correct, we should specify python2 or python3, because they can't interop and probably never will.
I think at this point we can rest easy that python2 has finally been fully purged from default installs. Heck a few weeks ago I installed Kubuntu 24.04 base and there was no Python at all...
Debian stable doesn't have "python" anywhere on my PATH, for a good reason IMHO. Shebangs say "/usr/bin/env python3" or hardcode "/usr/bin/python3".