Windows Python2 and Python3 coexist __python

Source: Internet
Author: User

Install Python2 and Python3
Download the Python2 and Python3 installation packages separately, and then install them separately. At the same time as the Python3 (>=3.3) installation, the installation package also installs the initiator Py.exein the system, located in the C:\Windows\ directory, as shown in the following figure:


If you have both Python 2 and Python 32 versions installed in your system, you can use the launcher to specify whether the version you want to run is 2 or 3 when you use Python on the command line.
    
2. Operation Example
To set up the Python file abc.py that you want to manipulate, you can run it in the following two ways.

    Mode one:

Use Python2
py-2 abc.py

//Use Python3
py-3 abc.py

    Mode two:
If you find it troublesome to specify a version every time on the command line, you can also add a version description in the code file that indicates the target version at the beginning of the code file.

Use Python2
#! python2

//Use Python3
#! Python3

After this is noted, the program will automatically recognize the target version when it is run, and you do not have to specify the version when you operate under the command line.

In command-line mode, you can do the following:
py abc.py

    
3. Use Pip

Python2
py-2-m pip install xxx

//python3
py-3-m pip install xxx

    
4. Use Chinese characters
To use Chinese characters in Python2, you need to indicate the encoding in the first line, so now when you specify Python, you should specify the version and encoding in the following order:

#! Python2
# Coding:utf-8

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.