Two versions of Python under Ubuntu toggle

Source: Internet
Author: User

Recently installed in Ubuntu16.04 python3.5 and the system comes with the python2.7.13, summarize the different versions of the switching problem.

    • Alias: Aliases
    • BASHRC: Personal Profile

First, modify the Python version (for users)

To modify a Python version for a particular user, simply create one (alias) in its home directory alias . Open the user's ~/.bashrc file and add the new alias information to modify the Python version that is used by default.

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

Once you have done this, log back in or reload .bashrc the file for the operation to take effect.

. ~/.bashrc

Check the current Python version.

Python--version

  

Second, modify the Python version (for the entire system)

The Python version can be modified throughout the system level with the Update-alternatives directive. The premise is to log in as the root user.

  • Go to root User:
    sudo-

    You will be prompted to enter password: Enter your password to log in.

  • If this is the first time to use root, Ubuntu system is not activated by default, the root user needs to be activated manually, terminal input:
sudo passwd root

Prompt: Enter new UNIX password:, enter the password as required, so that the activation is completed, sudo again-, login completed.

  • Su
    • SU//Switch to Super User
    • Su username//switch to username user
    • Su differs from sudo su: refer here.

After logging in to the root user, view all versions of Python:

Update-alternatives

If an error message appears:

Update-alternatives:error:no Alternatives for Python

This shows that Python alternatives is not update-alternatives recognized, and we need to update alternatives table to include Python 2.7 and python3.5.

update-alternatives:using/usr/bin/python2.7 to Provide/usr/bin/python (python) in Auto modeupdate-alternatives:using /usr/bin/python3.5 to Provide/usr/bin/python (python) in auto mode

This time the computer tip:syntax error near unexpected token ' (', which is not recognized (, need to be escaped:

update-alternatives:using/usr/bin/python2.7 to Provide/usr/bin/python \ (python\) in Auto modeupdate-alternatives: using/usr/bin/python3.5 to Provide/usr/bin/python \ (python\) in Auto mode

It also indicates an error:

No command ' update-alternatives: ' Found, did you mean:

Command ' update-alternatives ' from the package ' dpkg ' (main)

Update-alternatives:: Command not found

not resolved temporarily.

Reference:

    • Https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux

Two versions of Python under Ubuntu toggle

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.