How to change the default Python version In Debian Linux to an alternative version

Source: Internet
Author: User

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 uselsCommand to view which Python binary files are available in your system.

  1. $ ls/usr/bin/python*
  2. /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:

  1. $ python --version
  2. 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~/.bashrcFile to modify the default Python version.

  1. alias python='/usr/bin/python3.4'

After completing the preceding operations, log on again Or reload.bashrcFile to make the operation take effect.

  1. $ .~/.bashrc

Check the current Python version.

  1. $ python --version
  2. Python3.4.2

 

2. Modify the Python version at the system level.

We can useupdate-alternativesTo change the Python version for the entire system. Log on as a root user. First, list all available python alternative versions:

  1. # update-alternatives --list python
  2. 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-alternativesCommand recognition. To solve this problem, we need to update the alternative listpython2.7Andpython3.4Put it in.

  1. # update-alternatives --install /usr/bin/python python /usr/bin/python2.71
  2. update-alternatives:using/usr/bin/python2.7 to provide /usr/bin/python (python)inauto mode
  3. # update-alternatives --install /usr/bin/python python /usr/bin/python3.42
  4. update-alternatives:using/usr/bin/python3.4 to provide /usr/bin/python (python)inauto mode

--installMultiple 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.4The priority is set to 2, soupdate-alternativesThe command automatically sets it to the default Python version.

  1. # python --version
  2. Python3.4.2

Next, we will list available alternative Python versions.

  1. # update-alternatives --list python
  2. /usr/bin/python2.7
  3. /usr/bin/python3.4

Now, we can use the command below to switch between the listed Python replicas at any time.

  1. # update-alternatives --config python

  1. # python --version
  2. Python2.7.8

 

3. Remove the alternative version

Once a Python replacement version no longer exists in our system, we canupdate-alternativesDeleted from the list. For example, we can remove python2.7 from the list.

  1. # update-alternatives --remove python /usr/bin/python2.7
  2. update-alternatives: removing manually selected alternative - switching python to auto mode
  3. 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:

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.