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 Python executable binaries on the system. You can use the command as follows ls
to check which Python binaries are available on 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
Execute the following command to view the default Python version information:
$ python --version
Python 2.7.8
1. Modify the Python version based on the user:
alias
To modify the Python version for a specific user, just create an alias in their home directory . Open the user's ~/.bashrc
file and add new alias information to modify the default Python version.
alias python='/usr/bin/python3.4'
Once the above operation is completed, log in again or reload .bashrc
the file for the operation to take effect.
$ . ~/.bashrc
Check 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 an error message like the one shown above appears, it means that the alternative version of Python has not been update-alternatives
recognized by the command. To solve this problem, we need to update the substitution list to include python2.7
and .python3.4
# 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
--install
Options take several parameters for creating symbolic links. The last parameter specifies the priority of this option. If we do not set an alternative option manually, the option with the highest priority will be selected. In this example, we /usr/bin/python3.4
set the priority to 2, so update-alternatives
the command will automatically set it as the default Python version.
# python --version
Python 3.4.2
Next, we again list the available alternative versions of Python.
# update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.4
From now on, we can use the command below to switch between the listed alternative versions of Python at any time.
# update-alternatives --config python
# python --version
Python 2.7.8
3. Remove alternative versions
Once an alternative version of Python no longer exists on our system, we can update-alternatives
delete it from the 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
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 is proudly launched by Linux China
The pirated resources of "Celebrating More Than Years 2" were uploaded to npm, causing npmmirror to have to suspend the unpkg service. Microsoft's China AI team collectively packed up and went to the United States, involving hundreds of people. The founder of the first front-end visualization library and Baidu's well-known open source project ECharts - "going to the sea" to support Fish scammers used TeamViewer to transfer 3.98 million! What should remote desktop vendors do? Zhou Hongyi: There is not much time left for Google. It is recommended that all products be open source. A former employee of a well-known open source company broke the news: After being challenged by his subordinates, the technical leader became furious and fired the pregnant female employee. Google showed how to run ChromeOS in an Android virtual machine. Please give me some advice. , what role does time.sleep(6) here play? Microsoft responds to rumors that China's AI team is "packing for the United States" People's Daily Online comments on office software's matryoshka-like charging: Only by actively solving "sets" can we have a future