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.
As suggested in comments, you could create an alias as follows:
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 topython2
,python2
points topython2.7
.To achieve the same, use:
If you want
python
pointing to 3rd version, you could use the same, but the last command should be:Example
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 topython3
, you can simply installpython-is-python3
:After this, invoking
python
will work just fine.I had same error
you can try
this How to make 'python' program command execute Python 3? would help to make python alias.
Another option that would work across different (and older) versions of ubuntu is the "alternatives" system, either the command-line
update-alterantives
(should be installed) or guigalternatives
(not installed by default). It lets one configure your "preferred" version when you have multiple versions, or completely different but compatible implementations, (e.g. compilers, editors; see for example this dump:update-alternatives --get-selections
).To see which versions of python are currently the default (note: these are symbolic links to specific versions):
Usually (like, always, without exception) you want the default
python
to bepython2
, for compatibility reasons (otherwise you will breakapt
and other system utilities!) and then just explicitly invokepython3
if & when you really mean Python3.To see what current alternatives are configured for
python
:If alternatives are found, skip the following (see
--config
, below). Otherwise, we can configure both python2 and python3 as "alternatives" for thepython
command and you can switch between them (or just setpython2
here and you're done; the rest is here for completeness & as an exercise):(Important! if your default python is showing as
python3
, then change it here topython2
, otherwiseapt
and other system utilities may be broken!)To use
update-alternatives
to change the version currently selected, do the following and choose the version you want:To completely remove all
python
alternative configurations (e.g., to start over, or just undo everything if anything weird is going on):Most times you've to use the keyword python3 to run the code other than just python on py, these won't work as expected.