How do you run a Python program in the Linux terminal? Like this, right?
However, if you try to use the
python command in Ubuntu (and some other distributions), it will throw an error.
Command ‘python’ not found, did you mean:
command ‘python3’ from deb python3
command ‘python’ from deb python-is-python3
If you pay attention to the error message, it clears a lot of things. The python command is actually python3 here.
If you don’t understand it, no worries. I’ll explain things in detail here.
Why there is no python command found on Ubuntu?
It’s because the Python language is not installed as python but python3 or python2 (in some older Ubuntu versions).
At some point in time in the distant past, Python was actually available as
python package/executable. When Python released version 2, Ubuntu and other distros had to provide support for both Python version 1.x and 2.x.
So, they named the newer Python version
python2 to distinguish between the two. Other applications or libraries also specified python or python2 in their code.
Eventually, Python version 1 was discontinued completely but the package continued to be named python2.
Similarly, when Python version 3 was released, distributions started providing both
Python 2 is no longer supported and Python 3.x is what you get on Ubuntu. The package is still named python3.
To summarize, you have Python installed on Ubuntu already. It is available as python3 package.
So, what are your options when you see Python command not found error on Ubuntu? Let me go over them.
Make sure you have Python installed on your system
It should already be installed but no harm in double checking.
Ubuntu 18.04 had Python 2 as well but 20.04 and higher versions have Python 3 only. Still, which version(s) you have with:
type python python2 python3
As you can see in the screenshot below, I have Python version 3 installed on my system.