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