replace

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python3.5 3

with

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python3.5 3

e.g. installing into /usr/local/bin instead of /usr/bin.

and ensure the /usr/local/bin is before /usr/bin in PATH.

i.e.

[bash:~] $ echo $PATH
/usr/local/bin:/usr/bin:/bin

Ensure this always is the case by adding

export PATH=/usr/local/bin:$PATH

to the end of your ~/.bashrc file. Prefixing the PATH environment variable with custom bin folder such as /usr/local/bin or /opt/<some install>/bin is generally recommended to ensure that customizations are found before the default system ones.

Answer from jonrobm on Stack Overflow
Top answer
1 of 7
61

replace

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python3.5 3

with

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python3.5 3

e.g. installing into /usr/local/bin instead of /usr/bin.

and ensure the /usr/local/bin is before /usr/bin in PATH.

i.e.

[bash:~] $ echo $PATH
/usr/local/bin:/usr/bin:/bin

Ensure this always is the case by adding

export PATH=/usr/local/bin:$PATH

to the end of your ~/.bashrc file. Prefixing the PATH environment variable with custom bin folder such as /usr/local/bin or /opt/<some install>/bin is generally recommended to ensure that customizations are found before the default system ones.

2 of 7
47

Per Debian policy, python refers to Python 2 and python3 refers to Python 3. Don't try to change this system-wide or you are in for the sort of trouble you already discovered.

Virtual environments allow you to run an isolated Python installation with whatever version of Python and whatever libraries you need without messing with the system Python install.

With recent Python 3, venv is part of the standard library; with older versions, you might need to install python3-venv or a similar package.

$HOME~$ python --version
Python 2.7.11

$HOME~$ python3 -m venv myenv
... stuff happens ...

$HOME~$ . ./myenv/bin/activate

(myenv) $HOME~$ type python   # "type" is preferred over which; see POSIX
python is /home/you/myenv/bin/python

(myenv) $HOME~$ python --version
Python 3.5.1

A common practice is to have a separate environment for each project you work on, anyway; but if you want this to look like it's effectively system-wide for your own login, you could add the activation stanza to your .profile or similar.

🌐
GitHub
gist.github.com › joesan › c947ac9c9c3b851f818b29fe20084fdf
update-alternatives for python3 on Ubuntu · GitHub
Loads of solutions exist, but for changing the system default, alias is not the way to go. $ update-alternatives --list python update-alternatives: error: no alternatives for python
🌐
Medium
rem-baba.medium.com › python-version-switch-manager-f4e34b3c6d9e
Python version switch manager. The objective of this tutorial is to… | by Ramesh Babu Chayapathi | Medium
July 10, 2023 - To do so execute the following ... /usr/bin/python3m /usr/bin/python3-pasteurize · Step 2 Next, check if you already have some python alternatives configured....
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
As you can see, there are no alternatives for python any more. ... So, that’s how you use update-alternatives command on Ubuntu to switch between different versions of the same program or command very easily.
🌐
Ubuntu
bugs.launchpad.net › ubuntu › +bug › 1886098
Bug #1886098 “no alternatives for python” : Bugs : Ubuntu
/usr/bin/python2 /usr/bin/python3 · Revision history for this message · In Ubuntu, all python packages use explicit python3 or python2 interpreter and do not use unversioned /usr/bin/python at all.
Find elsewhere
🌐
Server Fault
serverfault.com › questions › 975785 › any-issue-with-using-update-alternatives-to-switch-python3-to-an-older-version
ubuntu - Any issue with using update-alternatives to switch python3 to an older version? - Server Fault
Looking at python3, we see that it is not a link to /etc/alternatives: $ ls -l /usr/bin/python3 lrwxrwxrwx 1 root root 9 Oct 25 2018 /usr/bin/python3 -> python3.6 · This symlink is installed by the python-minimal package: dpkg -S /usr/bin/python3 python3-minimal: /usr/bin/python3 · If you modify it, then if the python-minimal package is upgraded (for example by a security update), it will revert your changes and put the symlink back the way it was.
🌐
Ask Ubuntu
askubuntu.com › questions › 1099776 › question-about-python-mapping-etc-alternatives-python
16.04 - Question about Python mapping (/etc/alternatives/python) - Ask Ubuntu
I didn't really know what I was doing when I made this /etc/alternatives/python but I followed the instructions from this link https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu ... $ sudo update-alternatives --config python #Will show you an error: update-alternatives: error: no alternatives for python3 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1 $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2 $ sudo update-alternatives --config python
🌐
GitHub
gist.github.com › growtopiajaw › 7c5b7556c9b9a48aa68fe063107e1a5d
update-alternatives for python2 and python3 in Ubuntu 16.04.x · GitHub
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python2.7 2 sudo update-alternatives --config python3 There are 2 choices for the alternative python3 (providing /usr/bin/python3). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/python2.7 1 auto mode 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.5 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 2 · Done! Commands that requests for python, python2 or python3 will now work properly and say goodbye to errors!
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - sudo update-alternatives --install ... you encounter an error stating that there are no alternatives for a command, it’s likely that the alternative has not been installed yet....
Top answer
1 of 2
14

The reason is, python versions aren't fully compatibile. If you set 3.3 version as your default, the applications made for 2.7 could not work.

2 of 2
-3

Or maybe you can.

Important Note: The solution presented bellow (with update-alternatives) may break your system. If things break, try to fix them and keep python 3, report the fix you made to the correct bug-reports sites and help the community to grow; or move back to python 2. At the end of the answer I'll add a simple command to move back in case you need.

If you just want to change python for your own user, not the system, you can use an alias.

Solution 1: alias

Add this line into your ~/.bashrc or ~/.bash_aliases file:

alias python=python3

And that is it. You don't need to read bellow.

Solution 2: update-alternatives

If alias is not what you are looking for, and you really want to change the default of the whole system, then keep reading.

First check your python version:

# python -V
Python 2.7.13

Use this commands to install alternatives (run as root or use sudo)

# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

Then configure the version with (again, run also root or use sudo):

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Now check the version:

# python -V
Python 3.5.3

When you run the above command, you can choose selection number: 0 or 2 to pick python 3. If things break, run again and pick number 1 to go back to python 2.


Good readings:

python3 statement

Hack-a-Day

The Register News

🌐
Python.org
discuss.python.org › python help
Unable to upgrade Python 3.8.10 to 3.10 - SOLVED - Python Help - Discussions on Python.org
May 15, 2022 - Hi, I tried to upgrade Python 3.8.10 to 3.10 on Ubuntu : Ubuntu 20.04.4 LTS but we hit a blocker and wondering whether anyone is able to upgrade it successfully. We basically followed the following page for instructions: When we reached 2nd command in Step 3: Add Python 3.8 & Python 3.10 to update-alternatives, we see this error.
Top answer
1 of 1
7

To answer your first question

Why update-alternatives has not created the link in /usr/local/bin for maintaining for proper searching of application ?

This is simply because alternatives for python3 is configured at the moment to create the symbolic link in /usr/bin. From your output above:

sudo update-alternatives --config python3
There are 3 choices for the alternative python3 (providing /usr/bin/python3).
...

It pretty normal for any Linux distribution to search /usr/local/bin before /usr/bin for executables, as this gives you the freedom to put any binaries and libraries into /usr/local without interfering with the dpkg packages.

For you specific problem and from the output of sudo update-alternatives --config python3 I guess /usr/local/bin/python3 is a symbolic link to /usr/local/bin/python3.7

root@host:~# ls -l /usr/local/bin/python3
lrwxrwxrwx 1 root root 25 Sep 22 15:36 /usr/local/bin/python3 -> /usr/local/bin/python3.7

If that is the case, just remove the symbolic link /usr/local/bin/python3 and you should be fine, since when calling python3 only /usr/bin/python3 is found, which should point to /etc/alternatives/python3 which in turn should point to the selected binary.
If /usr/local/bin/python3 is not a symbolic link, rename it and configure update-alternatives appropriately.

While this might save you for now, the next update might render your configuration useless again. The symbolic link /usr/bin/python3 is shipped with the package python3-minimal and by managing this link with update-alternatives the symbolic link is broken from the view of the python3-minimal package. The next update of this package could fix this problem, but then the link is broken from the view of update-alternatives.

To come around both problems, it would be better to configure update-alternatives to use /usr/local/bin/python3 as the symbolic link providing the selected version.
To do so, the steps as follows should do the trick, including fixing the /usr/bin/python3 link.

sudo update-alternatives --install /usr/local/bin/python3 python3 /usr/bin/python3.6 2
apt-get install --reinstall python3-minimal