This article is linked from http://www.myhack58.com/Article/48/66/2016/71806.htm
When you install Debian Linux, it is possible for the installation process to provide you with multiple versions of Python available at the same time, so there will be more than one Python executable binary file in the system. You can use the LS command to see which Python binaries are available in your system, as in the following ways.
- $ 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
Execute the following command to view the default Python version information:
- $ python--version
- Python 2.7.8
1. Modify Python version based on User:
To modify the Python version for a particular user, simply create an alias (alias) in its home directory. Open the user's ~/.BASHRC file and add new alias information to modify the Python version that is used by default.
- Alias python= '/usr/bin/python3.4 '
Once you have done this, log back in or reload the. bashrc file for the operation to take effect.
- $ . ~/.bashrc
Check the current Python version.
- $ python--version
- Python 3.4.2
2. Modify the Python version at the system level
We can use Update-alternatives to change the Python version for the entire system. Log in as root and first list all available Python alternative version information:
- # update-alternatives--list python
- Update-alternatives:error:no Alternatives for Python
If the error message shown above is present, the alternate version of Python is not yet recognized by the update-alternatives command. To solve this problem, we need to update the alternate list and put python2.7 and python3.4 into it.
- # update-alternatives--install/usr/bin/python python/usr/bin/python2.7 1
- update-alternatives:using/usr/bin/python2.7 to Provide/usr/bin/python (python) in auto mode
- # update-alternatives--install/usr/bin/python python/usr/bin/python3.4 2
- update-alternatives:using/usr/bin/python3.4 to Provide/usr/bin/python (python) in auto mode
The--install option uses multiple parameters to create symbolic links. The last parameter specifies the priority of this option, and if we do not manually set the override option, then the option with the highest priority will be selected. In this example, we set the priority for/usr/bin/python3.4 to 2, so the update-alternatives command automatically sets it as the default Python version.
- # python--version
- Python 3.4.2
Next, we list the available Python replacement versions again.
- # update-alternatives--list python
- /usr/bin/python2.7
- /usr/bin/python3.4
From now on, we can use the commands below to switch freely in the list of Python alternatives at any time.
- # update-alternatives--config python
- # python--version
- Python 2.7.8
3, remove the replacement version
Once we no longer have an alternate version of Python in our system, we can remove it from the Update-alternatives list. For example, we can remove the python2.7 version 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) in auto mode
The default version of Python is switched to alternate version under Linux