[Go]windows multiple Python versions coexist, Pip uses

Source: Internet
Author: User

Multiple versions of Python coexist under Windows, and Pip usesSeptember 13, 2017 17:21:30Hits: 2574first, at the same time installed Python3 and Python2, how to distinguish

People who know Python know that Python has 2.x and 3.x versions, and python3.x versions are not backwards compatible, but depending on the specific needs, sometimes 2.x and 3.x coexist, Python coexistence itself is not a problem, just need to set some environment variables and modify something to make it easier to use. This article mainly describes the Windows environment

First of all, of course, install the two different versions of Python you need, here I install 2.7 and 3.5, two versions of the installation sequence does not matter.

The next step is to check the environment variables, the missing we need to add. Find the location of the environment variable first.

Check the following 4 variables in the PATH environment variable (the environment variables in path are separated by semicolons):

E:\Program files\python\python35-32\scripts\;

E:\Program files\python\python35-32\;

E:\Program files\python\python27\scripts\;

E:\Program files\python\python27\;

Then go to the Python2.7 installation directory to find the content and rename the Python.exe to Python2.exe

Then enter the python3.5 installation directory. Find the Python.exe program and rename it to Python3.exe

Finally, open the command-line interface to test it. Executing the python2 command enters the python2.7 interactive environment, and executing the PYTHON3 command enters the python3.3 interactive environment.

second, at the same time installed Python3 and Python2, how to use Pip?

At present, the domestic website will often let everyone change one of the Python.exe name (well, I also said, here to correct it), so that the name of the two executable file, but there is a major hidden danger, is that the name of the Python to modify the corresponding PIP will not be used.

What is the official solution?

In fact, the problem was that the Python community gave the official solution a few years ago, but it has not been noticed at home.

When we installed Python3 (>=3.3), the Python installation package actually installed a launcher Py.exe in the system, which was placed by default under Folder C:\Windows\. This initiator allows us to specify whether to run the code using PYTHON2 or Python3 (if you have successfully installed Python2 and Python3).

If you have a python file called tab.py, then you can run it with Python2 like this

Py-2 tab.py

Similarly, if you want to run it with Python3, that's it.

Py-3 tab.py

Remove Parameter -2/-3

Adding parameter -2/-3 to each run is still a hassle, so py.exe this launcher allows you to add a description to the code to indicate whether the file should be run by python2 or interpreted by Python3. The way to do this is to add a line at the beginning of the code file

#! Python2

Or

#! Python3

Indicates that the code file is run with Python2 or Python3 interpretation, respectively. This way, your commands can be simplified when you run them to

PY tab.py

Using PIP

When Python2 and Python3 are present on Windows, their corresponding Pip is called Pip.exe, so it is not possible to install the package directly using the PIP Install command. Instead, you use the initiator Py.exe to specify the version of the PIP. The command is as follows:

Py-2-m pip install XXXX

2 still means to run the PIP module using python2,-m pip, that is to run the PIP command. If the software is installed for Python3, then the command resembles

Py-3-m pip install XXXX

This article is from "Operation and maintenance record Mei Ling" blog, please be sure to keep this source http://meiling.blog.51cto.com/6220221/1863526

[Go]windows multiple Python versions coexist, Pip uses

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.