Shebang issue - Ubuntu does not link 'python' to 'python3' by default
I typically use #!/usr/bin/env python
as my shebang for Python stuff. I switched to Ubuntu (22.04) from Fedora (36) recently and found that when I tried to run something outside of a virtualenv it bombed out thusly:
/usr/bin/env: ‘python’: No such file or directory
This stackoverflow post offered two solutions:
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo apt install python-is-python3
The post that presented the latter pointed me at the package’s description:
Description-en: symlinks /usr/bin/python to python3
Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal)
releases, all python packages use explicit python3 or python2
interpreter and do not use unversioned /usr/bin/python at all. Some
third-party code is now predominantly python3 based, yet may use
/usr/bin/python.
.
This is a convenience package which ships a symlink to point
the /usr/bin/python interpreter at the current default python3. It may
improve compatibility with other modern systems, whilst breaking some
obsolete or 3rd-party software.
So, I see now. Fedora has a link from python
to python3
but Ubuntu does not, as of 20.04, apparently.
Personally I was OK with manually creating that symlink as opposed to using apt to install some package that claims to do that. I think it’s probably trustworthy but I still see more clearly what’s going on when I add the symlink myself. I did find this debian packages page which lists which files it installs. It doesn’t call /usr/bin/python out as a symlink though, just as a file that it would install.