Home >Backend Development >Python Tutorial >Detailed explanation of how to coexist between Python2 and Python3 versions under Windows
Preface
I have always used Python 3. Recently, I have been studying WeChat public account development. Each cloud platform only supports Python 2.7. If you want to use other versions, you need to set up your own environment. There is no information on developing WeChat public accounts with Python 3 on the Internet. I plan to use Python 2.7 first and then migrate to Python 3 when I have time to learn Docker.
After installing Python 2.7, scripts that originally worked normally under 3.4 cannot run. Some methods on the Internet are to rename the two versions of the main program to python2 and python3 respectively, judge the script with the human eye, and execute the script by manually entering the command line. Of course, lazy people like me who like to double-click and drag will not be satisfied and have found a smarter solution.
Python 2 and Python 3 coexist
When installing Python 3.3 or above, Python will install the launcher py.exe in the C:\Windows folder.
Double-click the script to call this program:
If both Python 2 and Python 3 exist in the system, you can use it to specify the version to run the code :
py -2 helloworld.py py -3 helloworld.py
2 and 3 are the versions.
It is too troublesome to add parameters every time. Specify the version directly on the first line of the Python script:
#! python3
You can double-click or command line Run:
py helloworld.py
If you do not specify the version on the first line and run or double-click the above command, it will call Python 2 by default
Use pip:
py -2 -m pip install requests py -3 -m pip install requests
-m pip means running the pip module
The original python and pip commands are still valid. Which version is executed by default? Look at the order of paths in the environment variables.
C:\Python34\;C:\Python34\Scripts;C:\Python27\;C:\Python27\Scripts;
As above, call Python 3
For more detailed explanations on the coexistence of Python2 and Python3 versions under Windows, please pay attention to PHP Chinese for related articles. net!