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
59.3k30 gold badges120 silver badges187 bronze badges
asked Dec 13, 2017 at 9:13
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
GAD3RGAD3R
59.3k30 gold badges120 silver badges187 bronze badges
14
You can achieve this by applying below simple steps -
- Check python version on terminal:
python --version
- Get root user privileges. On terminal type:
sudo su
- Type in your root password.
- Execute this command to switch to python 3.6:
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
- Check python version:
python --version
- Done.
answered Feb 2, 2019 at 9:37
Vineet JainVineet Jain
7735 silver badges2 bronze badges
7
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
IRSHADIRSHAD
4995 silver badges3 bronze badges
6
Using these commands can help you:
- check the version of python:
ls /usr/bin/python*
- alias:
alias python='/usr/bin/pythonxx'
[add this to. ~/.bashrc
] - re-login or source
. ~/.bashrc
- check the python version again:
python --version
answered Nov 8, 2018 at 11:44
NewtNewt
3492 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
9,8561 gold badge32 silver badges59 bronze badges
answered May 21, 2019 at 10:29
mmblackmmblack
1471 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
answered Dec 4, 2018 at 11:13
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
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
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