Linux switches Python2 and python3 to the default execution of versions (can also be used for the default execution of editors such as Sublime)

Source: Internet
Author: User
Tags switches

Using the alternate mechanism, you can freely switch to the Python default version by simply entering a few simple instructions at the terminal:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150

These two instructions add 2 alternate entries--install followed by the Python installation path

The last 100 and 150 parameters represent a non-specified run version priority

That is, after entering these 2 instructions, Python3 becomes the default execution version of the system.

So what do I do if I want to switch back to Python2?

Very simply, alternate allows us to specify the running version manually. In Terminal input:

sudo update-alternatives --config python

The terminal appears with the following prompt:

There are 2 candidates that can be used to replace Python (providing/usr/bin/python).


Select Path Priority state
------------------------------------------------------------
* 0/usr/bin/python3 150 Auto mode
1/usr/bin/python2 100 Manual Mode
2/usr/bin/python3 150 Manual Mode


To maintain the current value [*], press < Enter, or type the number you selected:

Then if you want to switch back to Python2, here I enter 1, and then press ENTER, you can switch back to the original version

Of course, this command also allows us to switch versions freely.

Linux switches Python2 and python3 to the default execution of versions (can also be used for the default execution of editors such as Sublime)

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.