Note: This method is only applicable to Debian-based Linux systems.
1. Check if there are python options and add
$ update-alternatives --display python
If the following information is prompted, it means that there is no optional item, and we need to add it ourselves.
update-alternatives: 错误: 无 python 的候选项
Add python2 and python3 option groups:
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2 # 添加Python2可选项,优先级为2,优先级高的数字大,此处设置python2优先级高于python3
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1 #添加Python3可选项,优先级为1
At this time, the python version is configured as python2.7, which can be queried with the following command:
$ python --version
2. Change the python system version
Open configuration options
$ update-alternatives --config python
According to the prompt, type in the version number you want to prioritize.
3. Remove the python version
$ sudo update-alternatives --remove python /usr/bin/python2.7