7

I want to update python3 to version 3.9, I ran

sudo apt update
sudo apt install software-properties-common
sudo -E add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.9
sudo update-alternatives --config python3

. All of which were successful apart from the last command. It gives update-alternatives: error: no alternatives for python3. Can somebody tell me what I am missing? Thanks!

3
  • If that's really the exact sequence you followed, seems like sudo apt install python3.9 should have failed: You didn't run another apt update after adding the PPA, so apt wouldn't know of the newly available packages. Check your apt log.
    – user535733
    Apr 22, 2022 at 15:34
  • python3.9 should never be an alternative. python3 should be an alternative. The command you pasted says you're running config on python3, yet it shouldn't complain for python3.9 unless you typed python3.9 there. Are you sure you ran the proper update-alternatives command?
    – Thomas Ward
    Apr 22, 2022 at 15:39
  • 1
    Thanks for your answers. I did indeed run another apt upgrade command after adding the ppa. Sorry, I was following instructions of a website and when pasting from the command line I thought it would not be important. @Thomas Ward sorry, that was a typo. It says "no alternatives for python3". Apr 22, 2022 at 16:01

4 Answers 4

9

To solve the error: no alternatives for python3 error message open the terminal and run the following command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
sudo update-alternatives --config python3
1
  • 2
    This solition not work: "update-alternatives: --install needs <link> <name> <path> <priority>"
    – Vitalicus
    May 15, 2023 at 13:24
5

DON'T upgrade the default python version of your system. You will break it. Instead, set up virtual environments to run specific Python versions.

0

Simple .sh script will solve the problem

i=0 ; for p in /usr/bin/python*.* ; do
update-alternatives --install /usr/bin/python python $p $((5 + i))
i=$((i+1))
done

Then

update-alternatives --config python
0

To solve the error: no alternatives for python3 error message open the terminal and run the following command:

sudo whereis python # for find path to python 3.9
sudo update-alternatives --install /usr/bin/python3 python3 /path/to/python3.9 2
sudo update-alternatives --config python3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .