Two ways to change the Ubuntu default Python version python-> Anaconda_python

Source: Internet
Author: User

You can use the LS command to see that Python binaries are available in your system as follows.

$ 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

Perform 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) under its home directory. Open the user's ~/.BASHRC file and add new alias information to modify the Python version used by default.

Alias python= '/usr/bin/python3.4 '

Once you have done so, log back in or reload the. bashrc file to make the operation effective.

$ . ~/.bashrc

Check the current Python version.

$ python--version
python 3.4.2

2. Modify Python version at System level

We can use Update-alternatives to change the Python version for the entire system. Log in as root, first listing all available Python alternative version information:

# update-alternatives--list python
update-alternatives:error:no alternatives for Python

If the error message shown above appears, 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 in 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 more than one parameter to create a symbolic link. The last parameter specifies the priority of this option, and if we do not manually set an alternate option, the option with the highest priority is selected. In this example, we set the priority for/usr/bin/python3.4 to 2, so the update-alternatives command automatically sets it to the default Python version.

# python--version
python 3.4.2

Next, we list the available Python alternate 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 at any time in the list of Python replacements.

# update-alternatives--config python

# python--version
python 2.7.8

3. Remove Alternate Version

Once a substitute version of Python is no longer present 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

Method 2, removing soft connections

Rm-rf/data/logs

ln-s/temp/logs/data/logs

Resolve Soft Connection LN error-bash:/usr/local/bin/mysql:too Many levels of symbolic links

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.