How to use Python version switching under PyQt5-windows

For Windows, it's a bit more complicated. Because regardless of python2 or python3, the python executable file is called python.exe, and the version number obtained by entering python under cmd depends on which version of the python path is higher in the environment variable. After all, windows searches in order. For example, the order in the environment variable is as follows:

Then the python version under cmd is 2.7.12.

Otherwise, it is the version number of python3.

 

This brings up a problem, if you want to run a script with python2, and then you want to run another script with python3, how do you do it? It is obviously troublesome to change environment variables back and forth.

Many methods on the Internet are relatively simple and crude. Rename two python.exe, one to python2.exe and one to python3.exe. This is certainly possible, but the way to modify the executable file is not a good way after all.

I carefully searched some python technical documents and found another solution that I think is better.

Borrow a parameter of py to call a different version of Python. py -2 calls python2, and py -3 calls python3.

When the python script needs python2 to run, just add it before the script, and then run py xxx.py.

#! python2

When the python script needs python3 to run, just add before the script, and then run py xxx.py.

#! python3

It's that simple.

At the same time, this perfectly solves the problem that pip reports an error in an environment where python2 and python3 coexist, prompting Fatal error in launcher: Unable to create process using '"'.

When pip for python2 is required, just

py -2 -m pip install xxx

When pip for python3 is required, just

py -3 -m pip install xxx

The pip packages of python2 and python3 can be perfectly separated in this way.

 

 

Welcome to join the technical discussion group, no ads, pure technology, welcome all big guys, newbies are also welcome, discrimination against novices is prohibited in the group, big guys answer questions voluntarily.

Guess you like

Origin blog.csdn.net/dongyunlong123/article/details/107844747