M HYPE SPLASH
// updates

python installed in ubuntu but python command not found

By Emma Payne

I have installed python 2.7 and python 3.7 in my ubuntu 18.04 but when i

type python it shows

 Command 'python' not found, but can be installed with: sudo apt install python3 sudo apt install python sudo apt install python-minimal You also have python3 installed, you can run 'python3' instead.

but i already installed python.

4

3 Answers

As suggested in comments, you could create an alias as follows:

alias python='python3'

by adding it to the ~/.bashrc file at the end of this file, exiting and reloading it in the current terminal using the next command: . ~/.bashrc

Or using linking:

As you can see below, my python points to python2, python2 points to python2.7.

To achieve the same, use:

sudo ln -s /usr/bin/python2.7 /usr/bin/python2
sudo ln -s /usr/bin/python2 /usr/bin/python

If you want python pointing to 3rd version, you could use the same, but the last command should be:

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

Example

$ whereis python
python: /usr/bin/python3.7 /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python3.7m-config /usr/bin/python3.7-config /usr/bin/python /usr/bin/python3.7m /usr/lib/python3.7 /usr/lib/python2.7 /usr/lib/python3.8 /etc/python3.7 /etc/python2.7 /etc/python /usr/local/lib/python3.7 /usr/local/lib/python2.7 /usr/include/python3.7 /usr/include/python2.7 /usr/include/python3.7m /usr/share/python /usr/share/man/man1/python.1.gz
user@lenovo:~$ ls -ailh /usr/bin/python*
1446954 lrwxrwxrwx 1 root root 7 жов 10 14:32 /usr/bin/python -> python2
1446952 lrwxrwxrwx 1 root root 9 жов 10 14:32 /usr/bin/python2 -> python2.7
1465834 -rwxr-xr-x 1 root root 3,6M лис 7 12:07 /usr/bin/python2.7
1447155 lrwxrwxrwx 1 root root 33 лис 7 12:07 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
1447156 lrwxrwxrwx 1 root root 16 жов 10 14:32 /usr/bin/python2-config -> python2.7-config
1442842 lrwxrwxrwx 1 root root 9 лют 12 00:23 /usr/bin/python3 -> python3.7
1449245 -rwxr-xr-x 2 root root 4,9M лис 20 11:21 /usr/bin/python3.7
1447339 lrwxrwxrwx 1 root root 33 лис 20 11:21 /usr/bin/python3.7-config -> x86_64-linux-gnu-python3.7-config
1449245 -rwxr-xr-x 2 root root 4,9M лис 20 11:21 /usr/bin/python3.7m
1447340 lrwxrwxrwx 1 root root 34 лис 20 11:21 /usr/bin/python3.7m-config -> x86_64-linux-gnu-python3.7m-config
1447341 lrwxrwxrwx 1 root root 16 жов 2 15:31 /usr/bin/python3-config -> python3.7-config
1442843 -rwxr-xr-x 1 root root 384 січ 30 2019 /usr/bin/python3-futurize
1442847 lrwxrwxrwx 1 root root 10 лют 12 00:23 /usr/bin/python3m -> python3.7m
1447342 lrwxrwxrwx 1 root root 17 жов 2 15:31 /usr/bin/python3m-config -> python3.7m-config
1442844 -rwxr-xr-x 1 root root 388 січ 30 2019 /usr/bin/python3-pasteurize
1447157 lrwxrwxrwx 1 root root 14 жов 10 14:32 /usr/bin/python-config -> python2-config
1455649 lrwxrwxrwx 1 root root 58 лип 10 2019 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
1450999 -rwxr-xr-x 1 root root 306 лип 10 2019 /usr/bin/pythontex3
4

This solution only applies to Ubuntu 20.04 (but sometimes people look at "similar issues" for a solution).

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.

10

I had same error

Ubuntu:/$ python
Command 'python' not found, but can be installed with:
sudo apt install python3
sudo apt install python
sudo apt install python-minimal
You also have python3 installed, you can run 'python3' instead.

you can try

Ubuntu:/$ python2.7
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> 

this How to make 'python' program command execute Python 3? would help to make python alias.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy