Summary: Ubuntu python2.x and python3.x coexist, and the Python version is set to 3

Source: Internet
Author: User

Environment: Just re-installed the system for Ubuntu16.04
Purpose: Install python3.x, this example installs 3.5.2
Steps:
1.$ python--version
Python 2.7---> system default installed Version
2. Download the corresponding version to https://www.python.org/downloads/
3. Install the downloaded version

    • Tar zxvf python-3.5.2.tgz
    • CD Python-3.5.2
    • ./configure--prefix=/usr/local/python-3.5.2 #重要, specify the installation path for Python and you can set it yourself.
    • Make
    • sudo make install

Issue One: You may encounter an error when executing sudo make install, similar to Zipimport. Zipimporterror:can ' t decompress data, missing zlib. Then another terminal: sudo apt-get update. Not enough, in the Ubuntu search box to enter update, select Software Updater, will be automatically check updates, at this time if you are prompted to update the software, click Update, restart the computer to take effect. At this point sudo apt-get install zlib can be installed successfully, then sudo make install can also succeed.

Question two: At this time Python--version, the system still returns the version of 2.7. However you want to use the 3.x version
Steps to resolve:

    • Which python2.7--->/usr/bin/python2.7
    • Which Python3--->/usr/bin/python3
    • Cd/usr/bin----> Modify the default Python version first
    • Rm-rf/usr/bin/python---> delete the corresponding soft link first
    • Ln-s/usr/bin/python3/usr/bin/python---> Create a soft link for Python3

At this point Python--version, it prompts Python 3.x

Issue three: Installing sudo apt-get install PYTHON-PIP will error: Importerror:no module named ' pip '; installation sudo apt-get install Python-setuptools succeeded, but is Easy_install--version will error: Pkg_resources. Distributionnotfound
Steps to resolve:

    • wget https://bootstrap.pypa.io/get-pip.py
    • sudo python get-pip.py

Again Easy_install--version; Pip--version, you can return the version number.

Summary: Ubuntu python2.x and python3.x coexist, and the Python version is set to 3

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.