For details about how Python 2 and Python 3 coexist in Windows, python2python3
Source: http://www.jb51.net/article/105311.htm
This article mainly introduces how Python 2 and Python 3 coexist in Windows. This article is very detailed and has some reference value for everyone. If you need it, let's take a look at it.
Preface
I have always used Python 3. Recently I have studied public account development. Each cloud platform only supports Python 2.7. To use other versions, you need to build your own environment. However, no public account for Python 3 can be found on the Internet. I plan to use Python 2.7 for the time being. If I have time to learn Docker, I will migrate it to Python 3.
After Python 2.7 is installed, scripts that can be normally used in Python 3.4 cannot run. Some methods on the Internet are to rename the main programs of the two versions to python2 and python3 respectively. The script is judged by the human eye and executed by the command line by hand. The lazy people like me who like double-click and drag will certainly not be satisfied and find a more intelligent solution.
Python 2 and Python 3 coexist
When Python 3.3 or a later version is installed, Python installs the initiator py.exe under the C: \ windowsfolder.
Double-click the script to call this program:
If both Python 2 and Python 3 exist in the system, you can use the specified version to run the Code:
py -2 helloworld.pypy -3 helloworld.py
2 and 3 are versions.
It is too troublesome to add parameters each time. You can directly specify the version in the first line of the Python script:
#! python3
You can double-click or run the following command:
py helloworld.py
If you run or double-click the preceding command without specifying a version in the first line, Python 2 is called by default.
Use pip:
py -2 -m pip install requestspy -3 -m pip install requests
-m pip
Indicates running pip Module
The original python and pip commands are still valid. Which version will be executed by default? Check the order of paths in environment variables.
C:\Python34\;C:\Python34\Scripts;C:\Python27\;C:\Python27\Scripts;
Call Python 3
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.