3

The latest updates of my Debian testing system removed Python version 2, and I only have Python 3 installed, with python3. There is no longer any command named python. This causes several scripts to fail, including scripts compatible with Python 3.

I would be interested in knowing what is the proper way to globally configure python as an alias for python3.

One dirty solution would be to manually do something like sudo ln -s /usr/bin/python{3,}, but I worry that this may not be robust to future APT updates (or if reinstalling Python 2 later). Another option is to set an alias, but then it would only work for my user, not for the entire system.

I also note that on Ubuntu there is a package python-is-python3 which does precisely this, but there is no such package on Debian.

2
  • I don't have a Debian system to test on, but can't you do this through update-alternatives? – terdon Sep 17 '20 at 12:47
  • Nope it doesn't seem to work. – a3nm Sep 17 '20 at 13:52
3

If you want to stick to the rule that everything in /usr apart from /usr/local should come from a package, I would actually download the python-is-python3 package and install that. It only ships the /usr/bin/python symlink and required documentation, and its package relations are unlikely to cause problems in the future.

An alias won’t help with your scripts’ shebangs, and given that the Python packages don’t use alternatives, creating your own alternative (update-alternatives etc.) wouldn’t be a robust solution.

If your scripts use /usr/bin/env python, you could manually add a link in /usr/local/bin instead.

Regardless of what you decide to do, from now on Python-dependent packages in Debian are required to explicitly use python2 or python3 in their shebangs, so you won’t run into problems caused by packages from the official repositories (in Debian 11 and later, excluding unstable and experimental for now since those still have old Python packages which haven’t been cleaned up yet).

1
  • This makes sense, thanks for the detailed answer – a3nm Sep 17 '20 at 13:52
3

It looks like Debian is now shipping python-is-python3 themselves (in sid and testing as of this writing), so the premise of the question no longer holds and you can just: sudo apt update && sudo apt install python-is-python3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.