Python2 and 3 compatibility issues on Windows

Source: Internet
Author: User

Python2 and 31 are installed in Windows, PIP packs problems, and the Python community gives the following solutions.

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 hello.py, then you can run it like this with Python2 py-2 hello.py similar, if you want to run it with Python3, so py-3 hello.py remove the parameter -2/-3 each run to add parameters-2 /-3 is still a bit of 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 #! /usr/bin/env Python2 or #! /usr/bin/env Python3 respectively indicates that the code file is run using Python2 or Python3 interpretation. This way, when running your command can be simplified for the Py hello.py using Pip, when Python2 and Python3 are present on Windows, their corresponding Pip is called Pip.exe, so can not directly use the PIP Install command to install the package. 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 you are installing software for Python3, then the command similar to py-3-m pip install Xxxx,python2 and 2 is added to the environment variable #! /usr/bin/env Python2 and #-*-Coding:utf-8-*-which one is written in front? There is another confusion for Python2 users, Python2 to add a line of instructions at the top of the code file to be able to use Chinese in the code. If you indicate that the Python version you are using also needs to add a line to the top of the file, which line should be on the first row? #! The python2 needs to be placed on the first line, and the coding instructions can be placed on the second line. So the file start should look like this: #! /usr/bin/env Python2
#-*-Coding:utf-8-*-

Python2 and 3 compatibility issues on Windows

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.