python27 and python35 coexist

   Sometimes when both python2 and python3 are needed, for example, opencv only supports python27, so how to call different pythons at any time.
   First, download and install two kinds of python, configure the environment variables, and then rename python.exe in D:\Python27 to python2.exe and it will be ok, enter python2 in cmd to enter the python2.7 compilation environment, enter python will enter the python3.5 compilation environment. When using pip to download other installation packages, enter python2 -m pip install numpy.



   When python27 is installed using pip, since the str of python2 is ascii encoding by default, which conflicts with unicode encoding, an error will be reported: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 108: ordinal not in range(128) and python3 Distinguish unicode str and byte arrary, and the default encoding is no longer ascii, this error will not be reported. If you want to use python2.7 to install through pip, you can directly specify the encoding method in the configuration file of python2. The file is in D:\Python27\Lib\ntpath.py, and add two sentences to the method def join: reload(sys);
sys .setdefaultencoding('gbk') is enough.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326854189&siteId=291194637