10

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

When type python3 on the terminal I get:

python 3.9.0

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

bash: python: command not found

And this happens to every Python program I try to install on my machine.

1
  • Which Linux distribution are you using (abd which version of it) and how did you install Python? Commented Dec 25, 2020 at 19:23

4 Answers 4

10

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)

Sign up to request clarification or add additional context in comments.

Comments

9

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.

1 Comment

python3 command is also not found so this is only helpful if there is python3
4

This error can be resolved, by simply linking.If you've got pytohn3 already installed, and still get the error "pytohn not found", try the below;

sudo ln -s /usr/bin/python3 /usr/bin/python

This utomatically links and aliases python to python3

Comments

1

Try python3 instead of python when running python program.

For example:

python3 -m venv venv

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.