13

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
    Commented Sep 17, 2020 at 12:47
  • Nope it doesn't seem to work.
    – a3nm
    Commented Sep 17, 2020 at 13:52

2 Answers 2

22

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

8

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).

2
  • 1
    This makes sense, thanks for the detailed answer
    – a3nm
    Commented Sep 17, 2020 at 13:52
  • Or correct the scripts to use /usr/bin/env python3. If the python standard had simply required a line declaring python3 from the beginning it would have prevented nearly every problem that was created by the version change, on all platforms.
    – Max Power
    Commented Feb 12, 2023 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .