Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Ubuntu has python3 but no python command

Errorpython: command not found

Short answer

Ubuntu names its interpreter python3, so typing python finds nothing. Install the python-is-python3 package: it just symlinks /usr/bin/python to python3. For a custom setup, register it with update-alternatives. Leave the system python3 itself to the package manager.

  • Applies to Ubuntu 24.04, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    See what exists: whether a python entry is there at all, and whether it is a link into the alternatives system.

    ls -l /usr/bin/python /usr/bin/python3
    update-alternatives --display python
  2. 2Match what you see, then jump to its fix

    1. 1ls says /usr/bin/python does not exist while /usr/bin/python3 doesNo package provides the python nameFix
    2. 2update-alternatives --display python shows nothing for python, or an older choice is pinnedYou manage the name yourself with update-alternatives and it is not registered or is stuckFix

What does the error look like?

  • python: command not found
  • /usr/bin/python: No such file or directory

Cause 1 of 2

No package provides the python name

1Check

On Ubuntu the interpreter is python3. A separate package supplies the unversioned name.

apt-cache policy python-is-python3

2Fix

Install python-is-python3. Its description is that it symlinks /usr/bin/python to python3.

sudo apt install python-is-python3

3Verify

python now reports a 3.x version.

python --version

Confirmed by packages.ubuntu.com

Did this fix it?

Cause 2 of 2

You manage the name yourself with update-alternatives and it is not registered or is stuck

1Check

The tool keeps a group per name. A group needs at least one registered path, and choosing one by hand with --config leaves it in manual mode until you run --auto.

update-alternatives --list python

2Fix

Register python3 as an alternative for python, then select it. The numbers are link, name, path and priority.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
sudo update-alternatives --config python

3Verify

The group points at python3.

update-alternatives --display python
python --version

Confirmed by manpages.ubuntu.com

Did this fix it?

How do I stop it coming back?

  • Write python3 in scripts and use shebangs of #!/usr/bin/env python3.
  • Work inside a virtual environment: python is always the right one there.
  • Never repoint /usr/bin/python3 itself; leave the system interpreter to the package manager.
  • If you installed the alternatives by hand, run update-alternatives --auto python to hand control back.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.