Update alternatives ошибка нет альтернатив для python

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!

asked Apr 22, 2022 at 13:36

Max Gabriel's user avatar

3

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

answered Apr 22, 2022 at 16:13

vanadium's user avatar

vanadiumvanadium

80.9k6 gold badges115 silver badges182 bronze badges

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

answered Apr 23, 2022 at 0:17

karel's user avatar

karelkarel

109k100 gold badges267 silver badges296 bronze badges

1

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

answered May 15 at 13:31

Vitalicus's user avatar

В Debian 9 установлены сразу 2 версии Python (из разных веток).

На момент написания заметки они были представлены пакетами python, который соответствует версии 2.7.13 из ветки 2.*; и python3 — версия 3.5.3 из ветки 3.*.

Само собой, по умолчанию используется только какая-то одна из версий, и для Debian это более старая версия 2.7.

Чтобы определить, какие версии Python установлены в вашей системе, выполните команды:

python --version

или

python -V

для определения точного номера версии из ветки 2.* (также эта команда показывает, какая версия Python используется в системе по умолчанию) и

python3 --version

или

python3 -V

которая покажет версию третьего Python.

Итак, предположим вы определии, что у вас установлена версия 2.7.13 второго Python, и она же используется как дефолтная.

Изменение версии Python, используемой по умолчанию

Для настройки переключения версий Python воспользуемся подсистемой альтернатив. Выполняем команду

update-alternatives --list python
update-alternatives: ошибка: нет альтернатив для python

Описание ошибки свидетельствует, что в системе нет настроеных для Python альтернатив.

Далее нужно определиться, нужна ли вам возможность переключения между версиями или вы просто хотите изменить используемую по умолчанию версию.

В первом случае мы сначала добавим в качестве альтернативы версию 2. Для этого определим местонахождение её бинарников

ls /usr/bin/python2*
/usr/bin/python2 /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python2-config

А затем установим версию 2.7 в качестве первой альтернативы (внимание, для этой операции требуются root привелегии)

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: используется /usr/bin/python2.7 для предоставления /usr/bin/python (python) в автоматическом режиме

Последний параметр в этом примере (единица) указывает на приоритет — чем больше цифра, тем он выше.

Далее делаем тоже самое с третьей версией. Определяем местоположение бинарников.

ls /usr/bin/python3*
/usr/bin/python3 /usr/bin/python3.5 /usr/bin/python3.5m /usr/bin/python3m

И добавляем версию в список альтернатив.

update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives: используется /usr/bin/python3.5 для предоставления /usr/bin/python (python) в автоматическом режиме

Если вы не планируете использовать вторую версию Python, то этап её добавления в таблицу альтернатив можно пропустить.

После этого команда python -V должна вернуть версию 3.5.3, что означает, что по умолчанию в системе используется третья версия Python.

Выполним повторно

update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5

и убедимся, что теперь у нас в системе в качестве альтернатив установлены две версии Python.

С этого момента мы в любое время можем переключиться на нужную версию с помощью команды

update-alternatives --config python
Есть 2 варианта для альтернативы python (предоставляет /usr/bin/python).

  Выбор   Путь            Приор Состояние
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         автоматический режим
  1            /usr/bin/python2.7   1         ручной режим
  2            /usr/bin/python3.5   2         ручной режим

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

© 2023 Scorpion’s Lair Sitemap

I am using Ubuntu 16.04 LTS . I have python3 installed. There are two versions installed, python 3.4.3 and python 3.6 . Whenever I use python3 command, it takes python 3.4.3 by default. I want to use python 3.6 with python3.

python3 --version shows version 3.4.3

I am installing ansible which supports version > 3.5 . So, whenever, I type ansible in the terminal, it throws error because of python 3.4

sudo update-alternatives --config python3
update-alternatives: error: no alternatives for python3

GAD3R's user avatar

GAD3R

62.7k31 gold badges130 silver badges192 bronze badges

asked Dec 13, 2017 at 9:13

codeclue's user avatar

8

From the comment:

sudo update-alternatives --config python

Will show you an error:

update-alternatives: error: no alternatives for python3 

You need to update your update-alternatives , then you will be able to set your default python version.

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

Then run :

sudo update-alternatives --config python

Set python3.6 as default.

Or use the following command to set python3.6 as default:

sudo update-alternatives  --set python /usr/bin/python3.6

answered Dec 14, 2017 at 12:11

GAD3R's user avatar

GAD3RGAD3R

62.7k31 gold badges130 silver badges192 bronze badges

14

You can achieve this by applying below simple steps —

  1. Check python version on terminal: python --version

  2. Execute this command to switch to python 3.6:

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1
    
  3. Check python version: python --version

  4. Done.

Kusalananda on strike's user avatar

answered Feb 2, 2019 at 9:37

user12979326's user avatar

2

if you have multiple version of python in your system. You just need to update the symbolic link of python inside /usr/bin/

root@irshad:/usr/bin# ls -lrth python*
lrwxrwxrwx 1 root root    9 Apr 16  2018 python -> python2.7
-rwxr-xr-x 1 root root 3.6M Nov 12  2018 python2.7
-rwxr-xr-x 2 root root 4.4M May  7 14:58 python3.6

In above example if you see the output of python --version you will get python2.7

Now update the python symlink using below command-

root@irshad:/usr/bin# unlink python
root@irshad:/usr/bin# ln -s /usr/bin/python3.6 python
root@irshad:/usr/bin# python --version
Python 3.6.8

answered May 25, 2019 at 18:03

IRSHAD's user avatar

IRSHADIRSHAD

5875 silver badges3 bronze badges

3

Using these commands can help you:

  1. check the version of python:
    ls /usr/bin/python*
  2. alias:
    alias python='/usr/bin/pythonxx' (add this to . ~/.bashrc)
  3. re-login or source . ~/.bashrc
  4. check the python version again:
    python --version

Verena Haunschmid's user avatar

answered Nov 8, 2018 at 11:44

Newt's user avatar

NewtNewt

3993 silver badges4 bronze badges

3

First check that you have a python3.6 folder?

ls /usr/bin/python3.6

If you have «python3.6» folder, you are good to go. Now update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1

then update new config for python3

sudo update-alternatives --config python3

Finally, check default python3 version:

python3 --version

Stewart's user avatar

Stewart

12.2k1 gold badge37 silver badges76 bronze badges

answered May 21, 2019 at 10:29

mmblack's user avatar

mmblackmmblack

1571 silver badge4 bronze badges

3

Create symlink for /usr/bin/python3.
In my LinuxMint:

# ls -lh /usr/bin/python3 /usr/bin/python
lrwxrwxrwx 1 root root 9 ноя 24  2017 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root 9 сен  6  2017 /usr/bin/python3 -> python3.5

# mv /usr/bin/python /usr/bin/python.bak
# cp /usr/bin/python3 /usr/bin/python
# python --version
Python 3.5.2

Adersh Ps's user avatar

answered Dec 4, 2018 at 11:13

nabi sheyhov's user avatar

1

An easy answer would be to add an alias for python3.6.

Just add this line in the file ~/.bashrc : alias python3="python3.6", then close your terminal and open a new one. Now when you type python3 xxx it gets translated to python3.6 xxx.

This solution fixes your problem without needing to tweak your system too heavily.

EDIT :

As Mikael Kjær pointed out, this is a misconfiguration of ansible with your system.

As seen here :

Set the ansible_python_interpreter configuration option to
/usr/bin/python3. The ansible_python_interpreter configuration option
is usually set per-host as an inventory variable associated with a
host or group of hosts:

  # Example inventory that makes an alias for localhost that uses python3
  [py3-hosts]
  localhost-py3 ansible_host=localhost ansible_connection=local

  [py3-hosts:vars]
  ansible_python_interpreter=/usr/bin/python3

As seen here about the config file :

Changes can be made and used in a configuration file which will be processed in the following order:

* ANSIBLE_CONFIG (an environment variable)
* ansible.cfg (in the current directory)
* .ansible.cfg (in the home directory)
* /etc/ansible/ansible.cfg

answered Dec 13, 2017 at 9:27

3

update-alternatives is to change system symlinks to user-defined/admin-defined symlinks.
If you have multiple versions of python3 installed in your system and want to control which python3 version to invoke when python3 is called. Do the following

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.4 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 2

Run below command if you want to change priority in the future.

update-alternatives --config python3

Explanation:-

sudo update-alternatives --install <symlink_origin> <name_of_config> <symlink_destination> <priority>

You can go on change name_of_config to python4, but then you have to invoke update-alternatives —config with python4 to reconfigure.

Using this approach you are able to control system python version and python3 version separately.

answered Mar 13, 2019 at 20:02

wittyurchin's user avatar

1

You can change the simbolic link by ln -sf python3.6 python3 inside /usr/bin. With this when you call python3 it will execute python3.6

answered May 21, 2019 at 10:42

SPAWN35's user avatar

You must log in to answer this question.

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

.

I was trying to set default python version to python3 in Ubuntu 16.04. By default it is python2 (2.7). I followed below steps :

update-alternatives --remove python /usr/bin/python2
update-alternatives --install /usr/bin/python python /usr/bin/python3

but I’m getting the following error for the second statement,

rejeesh@rejeesh-Vostro-1015:~$ update-alternatives --install /usr/bin/python python /usr/bin/python3
update-alternatives: --install needs <link> <name> <path> <priority>

Use 'update-alternatives --help' for program usage information.   

SuperStormer's user avatar

SuperStormer

4,9615 gold badges24 silver badges35 bronze badges

asked Feb 1, 2017 at 17:57

RejeeshChandran's user avatar

RejeeshChandranRejeeshChandran

4,1583 gold badges21 silver badges32 bronze badges

8

The second line mentioned can be changed to

[sudo] update-alternatives --install /usr/bin/python python /usr/bin/python3 10

This gives a priority of 10 for the path of python3.

The disadvantage of alternatively editing .bashrc is that using the commands with sudo will not work.

Nico Schlömer's user avatar

answered May 14, 2018 at 13:10

Pardhu's user avatar

11

EDIT:

I wrote this when I was young and naive, update-alternatives is the better way to do this. See @Pardhu’s answer.


Outdated answer:

Open your .bashrc file nano ~/.bashrc. Type alias python=python3
on to a new line at the top of the file then save the file with ctrl+o
and close the file with ctrl+x. Then, back at your command line type
source ~/.bashrc. Now your alias should be permanent.

Nico Schlömer's user avatar

answered Feb 1, 2017 at 18:17

Steampunkery's user avatar

SteampunkerySteampunkery

3,8432 gold badges19 silver badges28 bronze badges

9

To change Python 3.6.8 as the default in Ubuntu 18.04 to Python 3.7.

Install Python 3.7

Steps to install Python3.7 and configure it as the default interpreter.

  1. Install the python3.7 package using apt-get

    sudo apt-get install python3.7

  2. Add Python3.6 & Python 3.7 to update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
  1. Update Python 3 to point to Python 3.7

    sudo update-alternatives --config python3
    Enter 2 for Python 3.7

  2. Test the version of python

python3 --version
Python 3.7.1 

Alvin Sartor's user avatar

Alvin Sartor

2,1893 gold badges20 silver badges36 bronze badges

answered Aug 24, 2019 at 23:03

Purushottam Prabhakar's user avatar

5

If you have Ubuntu 20.04 LTS (Focal Fossa) you can install python-is-python3:

sudo apt install python-is-python3

which replaces the symlink in /usr/bin/python to point to /usr/bin/python3.

answered May 18, 2020 at 20:12

silviot's user avatar

silviotsilviot

4,5655 gold badges38 silver badges51 bronze badges

3

To change to python3, you can use the following command in terminal alias python=python3.

answered Feb 1, 2017 at 18:00

DanteVoronoi's user avatar

DanteVoronoiDanteVoronoi

1,1331 gold badge13 silver badges20 bronze badges

2

Update:
Since Ubuntu 20.04, the python3 is the default version, but still, python is not registered as python3 by default. In order to make that happen, you can simply do :

sudo apt install python-is-python3

For more information you can check this out.
Old way:

Do

cd ~
gedit .bash_aliases

then write either

alias python=python3

or

alias python='/usr/bin/python3'

Save the file, close the terminal and open it again.
You should be fine now! Link

answered Sep 15, 2017 at 18:34

Hossein's user avatar

HosseinHossein

24k34 gold badges119 silver badges222 bronze badges

1

A simple safe way would be to use an alias. Place this into ~/.bashrc file:
if you have gedit editor use

gedit ~/.bashrc

to go into the bashrc file and then at the top of the bashrc file make the following change.

alias python=python3

After adding the above in the file. run the below command

source ~/.bash_aliases or source ~/.bashrc

example:

$ python —version

Python 2.7.6

$ python3 —version

Python 3.4.3

$ alias python=python3

$ python —version

Python 3.4.3

Community's user avatar

answered Feb 9, 2018 at 10:32

Khan's user avatar

KhanKhan

1,24812 silver badges11 bronze badges

0

Just follow these steps to help change the default python to the newly upgrade python version. Worked well for me.

  • sudo apt-install python3.7 Install the latest version of python you want
  • cd /usr/bin Enter the root directory where python is installed
  • sudo unlink python or sudo unlink python3 . Unlink the current default python
  • sudo ln -sv /usr/bin/python3.7 python Link the new downloaded python version
  • python --version Check the new python version and you’re good to go

answered Dec 30, 2019 at 9:19

Shorya Sharma's user avatar

At First Install python3 and pip3

sudo apt-get install python3 python3-pip

then in your terminal run

alias python=python3

Check the version of python in your machine.

python --version

answered Nov 25, 2019 at 18:32

As an added extra, you can add an alias for pip as well (in .bashrc or bash_aliases):

alias pip=’pip3′

You many find that a clean install of python3 actually points to python3.x so you may need:

alias pip=’pip3.6′
alias python=’python3.6′

answered Mar 28, 2018 at 14:28

Paraic's user avatar

ParaicParaic

1371 silver badge6 bronze badges

This is a simple way that works for me.

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

You could change /usr/bin/python3 for your path to python3 (or the version you want).

But keep in mind that update-alternatives is probably the best choice.

answered Jan 15, 2021 at 14:18

cbcram's user avatar

cbcramcbcram

1652 silver badges6 bronze badges

As it says, update-alternatives --install needs <link> <name> <path> and <priority> arguments.

You have link (/usr/bin/python), name (python), and path (/usr/bin/python3), you’re missing priority.

update-alternatives --help says:

<priority> is an integer; options with higher numbers have higher priority in automatic mode.

So just put a 100 or something at the end

answered Feb 1, 2017 at 19:30

user7502402's user avatar

get python path from

ls /usr/bin/python*

then set your python version

alias python="/usr/bin/python3"

answered Oct 16, 2018 at 4:26

pradeep karunathilaka's user avatar

To change Python 3.6.8 as the default in Ubuntu 18.04 from Python 2.7 you can try the command line tool update-alternatives.

sudo update-alternatives --config python

If you get the error «no alternatives for python» then set up an alternative yourself with the following command:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

Change the path /usr/bin/python3 to your desired python version accordingly.

The last argument specified it priority means, if no manual alternative selection is made the alternative with the highest priority number will be set. In our case we have set a priority 2 for /usr/bin/python3.6.8 and as a result the /usr/bin/python3.6.8 was set as default python version automatically by update-alternatives command.

we can anytime switch between the above listed python alternative versions using below command and entering a selection number:

update-alternatives --config python

answered Jun 27, 2020 at 12:24

Ranjeet SIngh's user avatar

For another non-invasive, current-user only approach:

# First, make $HOME/bin, which will be automatically added to user's PATH
mkdir -p ~/bin
# make link actual python binaries
ln -s $(which python3) python
ln -s $(which pip3) pip

python pip will be ready in a new shell.

answered Mar 22, 2019 at 8:52

tdihp's user avatar

tdihptdihp

2,3092 gold badges23 silver badges40 bronze badges

Simply remove python-is-python2:

sudo apt purge python-is-python2

And install python-is-python3:

sudo apt install python-is-python3

It will automate the process of transition to new python3. Optionally you can get rid of remaining packages later:

sudo apt autoremove && sudo apt autoclean

answered May 25, 2020 at 8:22

Farab Alipanah's user avatar

0

Set priority for default python in Linux terminal by adding this:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1

Here, we set python3 to have priority 10 and python2 to priority 1. This will make python3 the default python. If you want Python2 as default then make a priority of python2 higher then python3

answered Nov 6, 2020 at 4:52

SouMitya chauhan's user avatar

       ~$ sudo apt-get install python3.9
/usr/bin$ cd /usr/bin
/usr/bin$ sudo unlink python3
/usr/bin$ sudo ln -sv /usr/bin/python3.9 python3
/usr/bin$ python3 --version
          Python 3.9.5
/usr/bin$ pip3 --version
          pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.9)

answered Jan 3, 2022 at 3:46

Udesh's user avatar

UdeshUdesh

2,2152 gold badges19 silver badges30 bronze badges

2

The best way in ubuntu 18.04 which will work for all users is

sudo vim /etc/bash.bashrc
add lines
alias python=python3
alias pip=pip3

Save the changes and restart .

After restart what ever version of python 3 you have in the system along with python 2.7 will be taken as default. You could be more specific by saying the following in alias if you have multiple version of python 3.

sudo vim /etc/bash.bashrc
add lines
alias python=python3.6
alias pip=pip3.6

answered Mar 22, 2019 at 10:12

Dr. Mian's user avatar

Dr. MianDr. Mian

3,26410 gold badges45 silver badges69 bronze badges

sudo rm /usr/bin/python3 #remove existing link
sudo ln /usr/bin/python3.8 /usr/bin/python3 # create a new link to the version of your choice

answered Oct 1, 2021 at 9:11

Sajibe Kanti's user avatar

1

To change the default python version in linux use following command-

sudo ln -sf /usr/bin/python3 /usr/bin/python2

This will change default version to python3

To verify use command-

python --version

answered Feb 20 at 12:13

Pranav Patil's user avatar

You didn’t include the priority argument

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 5

You can replace 5 with any priority you want. A higher priority alternative takes precedence over lower priority.

answered Sep 2, 2020 at 12:26

Vishad Goyal's user avatar

If there is a possibility to use particular python version directly, I would go for it compared to update-alternatives and alias solution.

Ex.

python3.6 -m pip install pytest
ptyhon3.6 -m pytest test_sample.py

-m executes particular module for that particular python version.
The first line will install pytest for for that particular version and user in possible location /home/user/.local/lib/python3.5/site-packages

answered Dec 15, 2021 at 1:21

JanPo's user avatar

JanPoJanPo

3252 silver badges8 bronze badges

At first, Make sure Python3 is installed on your computer

Go to your terminal and type:

cd ~/ to go to your home directory

If you didn’t set up your .bash_profile yet, type touch .bash_profile to create your .bash_profile.

Or, type open -e .bash_profile to edit the file.

Copy and save alias python=python3 in the .bash_profile.

Close and reopen your Terminal. Then type the following command to check if Python3 is your default version now:

python --version

You should see python 3.x.y is your default version.

Cheers!

answered Sep 21, 2019 at 19:13

nurealam siddiq's user avatar

1

On our Kali Linux (or any other Linux distribution) we might have installed different versions of Python. For using Python version 2.x we generally use python2 command, same as for using Python 3.x versions we use python3 command.

update alternatives: error no alternatives problem solved Linux

Here assume that we have installed multiple versions of Python3 installed on our system, like we have installed Python3.7 and Python 3.9 both on our Linux system for any reason. So whenever we want to use Python 3.9 we need to type command python3.9 because python3 command using Python 3.7 version as default.

python default version is lower

Our advanced Linux users may know this problem and the solution, but this is for beginners.

How to check installed Python versions on Linux?

This can be easily done with a simple command on our Terminal window. The command is following:

ls /usr/bin/python*

In the following screenshot we can see that we have Python2.7, Python3.7 and Python3.9 installed on our system.

Problem

But we can see that python3 command is choosing Python3.7 version as default. But some updated tools needs Python3.9 to run. We can run python3.9 command, but it is annoying we should run python3 to run Python3 latest version, we may modify our .bashrc/.zshrc file but that will not be the correct solution.

We need to set our update-alternatives for python3.

We can check for the alternatives of python3 by running following command:

sudo update-alternatives --config python3

But here we might get an error «update-alternatives: error: no alternatives for python3«.

update-alternatives: error: no alternatives for python3

It means, first we need to set alternatives for python3.

Solved

To set the alternatives for python3 we need to run some commands on our terminal.

First of all we need to run the following command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1

This command will add Python 3.7 on option 1.

Then we need to run following command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

This command will add Python 3.9 on option 2

We can see this on the following screenshot:

Python Alternatives set

Now we can again run the configure command to check and set the alternatives:

sudo update-alternatives --config python3

In the following screenshot we can see that now we can save the configurations now.

python3 alternatives

Here we can set the default version for the python3. Here automatically 0 is chosen for Python 3.9 version, we can go for it, otherwise instead of choosing by numbers we can run following command to choose the default python3 version:

sudo update-alternatives  --set python3 /usr/bin/python3.9

Now we can check python3 default version by using following command:

python3 -V

We can see that now our Python 3.9 version is set as default for python3 command:

python3 latest version set as default

«update-alternatives: error: no alternatives for python3» is a very common problem for beginners so we thought to write an entire article for it we got too much request to solve this on our Telegram DM. When Python 4 will release some versions of Python 4, we can use the same as we did for Python 3.

Love our articles? Make sure to follow us to
get all our articles directly on inbox. We are also available on Twitter and GitHub, we post article updates there. To join our family, join our Telegram Group. We are trying to build a community for Linux and Cybersecurity. For anything we always happy to help everyone on the comment section. As we know our comment section is always open to everyone. We read each and every comment and we always reply.

  • Update alternatives ошибка нет альтернатив для java
  • Upc exe ошибка приложения
  • Upc exe ошибка uplay
  • Upc exe ошибка ubisoft
  • Uo184 ошибка митсубиси аутлендер xl