python command not found on linux

Viewed 4716

I have a problem while running python on linux, I have python3 already installed.

When type python3 on the terminal i got:

python 3.9.0

When I run any program I made with for example python I got this error

bash: python: command not found

And this happen to every python program I try to install on my machine.

3 Answers

Place the below line in ~/.bashrc file:

alias python=python3

After inserting run the below command:

source ~/.bashrc

.bashrc is the configuration file for bash, a linux shell/command interpreter. An alias is a substitute for a (complete) command. It can be thought of as a shortcut. By adding the above line, an alias is created for python3 in the name of python. Now the programs using python instead of python3 should work fine without any error.

I had the same error too with Ubuntu 20.04, in the case you like "python" to refer to "python3", you can simply install python-is-python3:

sudo apt-get install python-is-python3

After this, invoking python will work just fine

I verified this solution only with Ubuntu 20.04 (18.x has not this package)

Try "python3" instead of "python" when you run python program.

For example:

python3 -m venv venv
Related