About Me

header ads

[Solved] “Command ‘python’ not found” Error in Ubuntu Linux

python-command-not-found-error-in-ubuntu

How do you use the Linux terminal to start a Python program? similar like this, yes?

python program.py

On the other hand, using the python command in Ubuntu (and certain other distributions) will result in an error.

Command ‘python’ not found, did you mean:

command ‘python3’ from deb python3

command ‘python’ from deb python-is-python3

The error message clarifies several things if you read it carefully. In this case, python3 is the real Python command.

It's okay if you don't understand. I'll go into more depth here.

Why can't I find a Python command in Ubuntu?

To differentiate between the two, they gave the newest Python version the name python2. Python or Python2 was also mentioned by other programs or libraries in their code.

In the end, Python version 1 was fully abandoned, although the package's name remained python2.

Similar to this, distributors began offering both python2 and python3 packages when Python version 3 was released.

Python 2 is no longer supported, and Ubuntu only includes Python 3.x. The package's name is still Python 3.

In conclusion, Python is already installed in Ubuntu. It may be found as a Python 3 package.

What choices do you have then when Ubuntu reports a Python command not found an error? I'll go through them now.

Make sure Python is installed on your computer

Although it ought to be installed already, it doesn't hurt to check.

Ubuntu 18.04 also supported Python 2, however only Python 3 is available in 20.04 and later versions. Which version(s) do you still have with:

type python python2 python3

The command below will install Python version 3 if you don't already have it installed:

sudo apt install python3

Instead of Python, use Python 3

Use the python3 command wherever possible in place of the python command, if it isn't too much bother for you.

Want to know what version of Python is installed? Use it as follows:

python3 --version

Additionally, the output includes version information:

Example:~$ python3 --version

Python 3.10.4

If you must run a Python application, run it as follows:

python3 program.py

In most situations, this ought to work for you. You'll run into problems if you're running a (old) Python program that expects to launch the python executable in its code. Don't worry; there are ways to avoid it as well.

Connect Python3 as Python

In your .bashrc file, you may establish a permanent alias as follows:

alias python='python3'

In this manner, your computer will launch Python3 when you use the python command.

Most of the time, it will function unless an application demands that /usr/bin/python be launched. Currently, a symlink between /usr/bin/python and /usr/bin/python3 is possible, but Ubuntu users have an easier solution.

If you install the python-is-python3 package for Ubuntu 20.04 and later, a package that automatically creates all links is available. This is also what the first error notice implied.

sudo apt install python-is-python3

Symlinks may be shown to have been generated, and the python command (which executes Python 3) can be used without any problems.

This should put the Python package on Ubuntu in the clear. Please let me know if you have any questions or recommendations.

Post a Comment

0 Comments