Version management of python

How to easily switch between different python environments in linux environment? The update-alternatives tool can help us accomplish this task very conveniently. In the Windows environment, it can be done through anaconda.

1. Manage python version switching through the update-alternatives tool

2. Use of update-alternatives:

 

 

3. Create configurations of different versions of python and set priorities
. Complete
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 152
<link> <name through the --install command of update-alternatives > <path> <priority>
<name> Specify a group name; I am here to manage the version switching of python, so I will name it python, and a python file will generally be generated under /etc/altenatives; if you want to Version management of other tools, such as java, then you can name it java.
<link> is a soft link generated by alternatives, pointing to /etc/alternatives/python
<path> is the path to the actual python executable

My environment is currently configured with python3 as auto mode. As can be seen from the above path information, /usr/bin/python points to /etc/alternatives/python, and /etc/alternatives/python points to /usr/bin/python3.

4. Check the python version configuration
frank@frank:/etc/alternatives$ 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 152 auto mode
1 /usr/bin/python2 151 manual mode
* 2 /usr/bin/python3 152 manual mode

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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325319588&siteId=291194637