Ubuntu has python3 but no python command
python: command not foundShort 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.
Fix it fast
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 python2Match what you see, then jump to its fix
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-python32Fix
Install python-is-python3. Its description is that it symlinks /usr/bin/python to python3.
sudo apt install python-is-python33Verify
python now reports a 3.x version.
python --versionConfirmed by packages.ubuntu.com
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 python2Fix
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 python3Verify
The group points at python3.
update-alternatives --display python
python --versionConfirmed by manpages.ubuntu.com
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:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Servers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
cv2.imshow raises 'not implemented' because the wrong OpenCV package is installed
cv2.imshow() works in one environment and fails in another
The headless OpenCV packages are built without any GUI code, so cv2.imshow cannot open a window.
2 causes, each with a fixServers
pip install Cython succeeded, but the shell cannot find cythonize
a pip warning that a script was installed to a directory outside PATH
pip put the cythonize script in a folder your shell does not search.
3 causes, each with a fixServers
Django returns a 500 behind Gunicorn and the traceback is nowhere
The traceback shows locally with runserver but not under Gunicorn
With DEBUG set to False, Django's default logging does not print errors to the console.
2 causes, each with a fixServers
Docker build fails with apk: not found in a Python or Ubuntu image
/bin/sh: 1: apk: not found
apk is the package manager of Alpine Linux only.
2 causes, each with a fixServers
You cannot pip install packages inside an Ubuntu Docker container
error: externally-managed-environment
If pip is missing, install the python3-pip package with apt, in the same RUN as apt-get update.
3 causes, each with a fix