Ubuntu16.04 switch python version

Python2.7 and python3.5 have been installed by default in ubuntu16.04

hanli@ubuntu:/usr/bin$ ls |grep python
dh_python2
dh_python3
python
python2
python2.7
python2.7-config
python2-config
python3
python3.5
python3.5m
python3m
python-config
x86_64-linux-gnu-python2.7-config
x86_64-linux-gnu-python-config

How to switch?

  1. It is now 2.7
hanli@ubuntu:/usr/bin$ python
Python2.7.12(default,Nov192016,06:48:10)
  1. Execute two commands
hanli@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python)in auto mode
hanli@ubuntu:/usr/bin$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python)in auto mode
  1. Check it again has become 3.5
hanli@ubuntu:/usr/bin$ python
Python3.5.2(default,Nov172016,17:05:23)
  1. How to switch at will
hanli@ubuntu:/usr/bin$ 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   150       auto mode
 1   /usr/bin/python2   100       manual mode
 2   /usr/bin/python3   150       manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode

# Before the number*The sign means the current version, enter 1 to switch to 2.7. Check again as follows

hanli@ubuntu:/usr/bin$ 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   150       auto mode
* 1   /usr/bin/python2   100       manual mode
 2   /usr/bin/python3   150       manual mode

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

Recommended Posts

Ubuntu18.04 switch Python version
Ubuntu16.04 switch python version
Install TensorFlow (python2.7 version) on Ubuntu
Ubuntu16 upgrade Python3
ubuntu18.04 install python2
Relearn ubuntu --python3
ubuntu12.04 install python3
ubuntu18.04 install python
ubuntu16.04 upgrade python2
Install the latest Python 3.6 version on Ubuntu
ubuntu configuration python, Red
Python MySQLd under Ubuntu
[python] python2 and python3 under ubuntu
Install Python3 on Ubuntu 14.04
Python virtual environment: Ubuntu16.04
Install python in Ubuntu
Install Python3 on Ubuntu 16.04
python tic-tac-toe-text version (part 2)
PyCharm set Python version
Install Python3.7 on Ubuntu
python Tic-Tac-Toe-text version (on)
Install Python 3.7 on Ubuntu 18.04 LTS
ubuntu sets python2.5 environment variables
ubuntu18.04 compile and install python3.8
ubuntu view python installation path
Python implements text version minesweeper
Python version of OpenCV installation
ubuntu build python development environment
Ubuntu 16.04 cannot switch root permissions
ubuntu offline installation python environment
How to install Python 3.8 on Ubuntu 18.04
Python version business card management system
Python Chinese encoding setting under ubuntu
Install Python virtual environment on Ubuntu 18.04
Openstack G version Ubuntu13.04 three-node experiment record
Error when installing Python module on Ubuntu
Ubuntu18.04 Server version installation and use (graphic)
Install fonts on Ubuntu and switch default fonts
Why doesn&#39;t Python support the switch statement?
How to install Python2 on Ubuntu20.04 ubuntu/focal64
Deploy python3 and nginx projects on ubuntu18.04
The relationship between Open3D version and Ubuntu
Install jetty in Ubuntu 18.04 Server, non-apt version
Use python3 to install third on ubuntu
Build a python development environment under Ubuntu
Why doesn&#39;t Python support the switch statement?
Python implements AI automatic version greedy snake