How to change the default Python version In Debian Linux to an alternative version
When you install Debian Linux, the installation process may provide you with multiple available Python versions at the same time, so there will be multiple executable binary files of Python in the system. You can usels
Command to view which Python binary files are available in your system.
$ ls/usr/bin/python*
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7/usr/bin/python3 /usr/bin/python3.4/usr/bin/python3.4m/usr/bin/python3m
Run the following command to view the default Python version:
$ python --version
Python2.7.8
1. Modify the Python version based on the user:
To modify the Python version for a specific user, you only need to createalias
(Alias. Open the user's~/.bashrc
File to modify the default Python version.
alias python='/usr/bin/python3.4'
After completing the preceding operations, log on again Or reload.bashrc
File to make the operation take effect.
$ .~/.bashrc
Check the current Python version.
$ python --version
Python3.4.2
2. Modify the Python version at the system level.
We can useupdate-alternatives
To change the Python version for the entire system. Log on as a root user. First, list all available python alternative versions:
# update-alternatives --list python
update-alternatives: error:no alternatives for python
If the above error message is displayed, it indicates that the replacement version of Python has not beenupdate-alternatives
Command recognition. To solve this problem, we need to update the alternative listpython2.7
Andpython3.4
Put it in.
# update-alternatives --install /usr/bin/python python /usr/bin/python2.71
update-alternatives:using/usr/bin/python2.7 to provide /usr/bin/python (python)inauto mode
# update-alternatives --install /usr/bin/python python /usr/bin/python3.42
update-alternatives:using/usr/bin/python3.4 to provide /usr/bin/python (python)inauto mode
--install
Multiple parameters are used to create symbolic links. The last parameter specifies the priority of this option. If we do not manually set an alternative option, the option with the highest priority will be selected. In this example/usr/bin/python3.4
The priority is set to 2, soupdate-alternatives
The command automatically sets it to the default Python version.
# python --version
Python3.4.2
Next, we will list available alternative Python versions.
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4
Now, we can use the command below to switch between the listed Python replicas at any time.
# update-alternatives --config python
# python --version
Python2.7.8
3. Remove the alternative version
Once a Python replacement version no longer exists in our system, we canupdate-alternatives
Deleted from the list. For example, we can remove python2.7 from the list.
# update-alternatives --remove python /usr/bin/python2.7
update-alternatives: removing manually selected alternative - switching python to auto mode
update-alternatives:using/usr/bin/python3.4 to provide /usr/bin/python (python)inauto mode
You may also like the following article about Python:
Installation of Python in Linux and precautions
Install and use the Python rq module in Ubuntu 14.04
Directly run Python code without the need for the operating system
Install Python3.4 on CentOS source code
Python core programming version 2. (Wesley J. Chun). [Chinese version of hd pdf]
Python development technology details. (Zhou Wei, Zong Jie). [hd PDF scan version + book guide video + code]
Obtain Linux information using a Python script
Build a desktop algorithm transaction research environment using Python in Ubuntu
A Brief History of Python Development
Python details: click here
Python: click here
Via: http://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux
Translator: mr-ping Proofreader: wxy
This article was originally compiled by LCTT and launched with the honor of Linux in China
This article permanently updates the link address: