For details about how Python 2 and Python 3 coexist in Windows, python2python3

Source: Internet
Author: User

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 pipIndicates 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.

Related Article

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.