How to switch the default Python version in Debian

Source: Internet
Author: User


When you install Debian Linux, the installation process may also provide you with multiple versions of Python available, so there will be more than one Python executable binary file, you can use the LS command in the following ways to see that your system has those Python binary files can be For use:

$ 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

Then execute the following command to view the default Python version information:

$ python--version python 2.7.8
To modify the Python version based on the 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
To modify the Python version based on the system:

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
To remove an alternate 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-SW Itching python to Auto mode update-alternatives:using/usr/bin/python3.4 to Provide/usr/bin/python (python) in auto mode

This article was reproduced from:http://www.linuxprobe.com/debian-switch-python.html

more Linux Dry Goods visit:http://www.linuxprobe.com/

How to switch the default Python version in Debian

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.