Install both Python2 and Python3 on the same computer

Source: Internet
Author: User

Install both Python2 and Python3 on the same computer(transferred from Zhengyihan, blog home: http://www.cnblogs.com/zhengyihan1216/)

There are currently two versions of Python, Python2 and Python3, and these two editions are being updated and maintained at the same time.

Whether to choose Python2 or select Python3 depends on which version the framework supports and which one is currently being used.

For example: Htmltestrunner, Locustio support Python2, but Python3 is not supported.

So a lot of times, you need to install Python2 and Python3 on a single computer.

This article is mainly about how to install both Python2 and Python3 on the same computer, and PIP can be used normally.

First, install Python2 (and PIP)

1.1, to Python's official website https://www.python.org/download the python installation file,

For Windows users, select the x86 version if it is a 32-bit system, or the 64 version of the installation file if it is a 64-bit system.

My own computer is 64 bits, the following example is described in 64 bits.

The name of the downloaded installation file looks like this: Python-2.7.12.amd64.exe

1.2, click "" "Python-2.7.12.amd64" "This installation file, always click on Next, in the selection of installation path need to pay special attention: Python installation path can not have spaces!

To differentiate between Python2 and Python3, rename the Python.exe file under this directory to Python2.exe, as shown below:

1.3. Add Python2 Environment variables

This computer--properties--Advanced system settings--advanced--environment variables--System Variables--path--Edit

Add at this point; E:\setup\Python27\Scripts\;   E:\setup\Python27\; (here according to their own installation path to write, and pay attention to the English semicolon and other variable values separated;

If you do not configure this variable, you will be prompted "not internal command" when entering Python2 in cmd)

1.4, in the cmd, input Python2, if the prompt appears, it indicates Python2 installation success

1.5, install Setuptools.

The PIP to be installed in step 1.6 depends on setuptools, so you need to install Setuptools before installing PIP.

To the official website https://pypi.python.org/pypi/setuptools download, the name resembles this appearance "" Setuptools-28.7.0.zip "" (Download time is different, the version number may be different), the decompression;

In cmd, go to the extracted directory (both setup.py file exists directory), execute >python2 setup.py Install (note: Because the Python.exe file is renamed in step 1.2 earlier in order to Python2.exe, So here Be sure to write python2 instead of Python when you enter a command

1.6. Install Pip

Pip is a tool for installing and managing Python packages, and it's easy to install Python packages with PIP.

To the official website https://pypi.python.org/pypi/pip, download Pip's compressed file, after downloading the name resembles this appearance "" Pip-8.1.2.tar "" (Download time is different, the version number may be different), the decompression;

In cmd, go to the extracted directory (both setup.py file exists directory), execute >python2 setup.py Install (note: The command executed here is Pytho2, not python, for the same reason as 1.5)

At this point we look at the Python2 pip installation directory E:\setup\Python27\Scripts, see below, there are Pip, pip2.7, PIP2, indicating that at this time in cmd execution pip or pip2.7 or PIP2, the execution of all It's Python2 's PIP.

1.7, in the cmd input pip2 or pip2.7, if the following content, indicating PIP installation success

Second, install the Python3 (because Python3 comes with PIP, so no additional PIP installation)

2.1, to Python's official website https://www.python.org/Download the Python3 installation file,

For Windows users, select the x86 version if it is a 32-bit system, or the 64 version of the installation file if it is a 64-bit system.

My own computer is 64 bits, the following example is described in 64 bits.

The name of the downloaded installation file looks like this: Python-3.5.0-amd64.exe

2.2, click "" "Python-3.5.0-amd64.exe" "This installation file, always click on Next, in the selection of installation path need to pay special attention: Python installation path can not have spaces!

2.3. Check if the PYTHON3 environment variable is added

Python3 can choose to add environment variables automatically at the time of installation, but sometimes it can't be added automatically, so be sure to check it yourself at this point.

This computer--attribute--Advanced system settings--advanced--environment variable--system variable--path

If there is no environment variable for Python3, add it here; E:\setup\Python35\Scripts\;   E:\setup\Python35\; (this is written according to your actual installation path)

2.4, check whether Python3 installation is successful, enter Python in cmd, if shown as shown, is about Python3 version, then Python3 installation is successful.

You may have questions: Why not enter Python3 here? A: Because there is no modification to the E:\setup\Python35 directory, the name of the Python.exe file is Python3.exe. Python2 made a change, so it doesn't matter if you modify it here, as long as it is able to work with E:\setup\ The Python.exe file under the Python27 directory does not have duplicate names.

2.5. Verify that the PIP in Python3 is automatically installed successfully

Enter PIP3 or pip3.5 in cmd (at which point the PIP does not appear to be Python2 or Pip in Python3), if there is a display in the Python3, the PIP automatically installs successfully.

You may have questions at this point, how do you know whether to enter PIP3 or pip3.5 instead of pip3.6? Because the name of the Pip.exe file under the E:\setup\Python35\Scripts directory is determined as follows:

The above one and two will be python2 and Python3 as well as the respective PIP installation completed.

Third, the specific use

If the PIP operation is used in Python2, use PIP2 or pip2.7 related commands.

Example: Install selenium for Python2, enter PIP2 install selenium in cmd or pip2.7 install Selenium

If the PIP operation is used in Python3, use PIP3 or pip3.5 related commands.

Example: Install selenium for Python3, enter PIP3 install selenium in cmd or pip3.5 install Selenium

If the package does not support the installation of PIP, the corresponding file download extracted into a directory, with CMD into the extracted directory

If the package is installed for Python2, execute python2 setup.py install

If the package is installed for Python3, execute the python setup.py install

If the content of the text is wrong, I hope you correct me, thank you.

Install both Python2 and Python3 on the same computer

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.