At the same time installed Python3 and Python2, how to use Pip?

Source: Internet
Author: User
Tags virtualenv
Ubuntu13.04, Python3.3 and 2.7 are installed in the system.
Use sudo apt-get install Python-pip
sudo apt-get install Python3-pip
Each of the two versions corresponds to a PIP

But now running PIP install only to the 2.7 version of the installation library (as if the name can only call Python-pip), how to set up for the 3.3 version of the installation?

Reply content:

Python3 with PIP3PIP,PIP2,PIP3 for Linux

Py-2-m pip install sth,py-3-m pip install sth for Windows See official documentation自带py2.7,自己安装了pip
Reprint-[Official Solution]windows on Python2 and 3 how compatible

Want to learn Python3, but temporarily without Python2. How do you make them coexist on Windows?

At present, the domestic website will often let everyone change one of the Python.exe name (well, I also said, here to correct it), so that the name of the two executable file, but there is a major hidden danger, is that the name of the Python to modify the corresponding PIP will not be used.

What is the official solution?

In fact, the problem was that the Python community gave the official solution a few years ago, but it has not been noticed at home.

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

For Python2 and 3 installations, see the Python tribe (http/ Academy--- 0 Basic 1 hours, the first section of getting started with Python.

If you have a python file called, then you can run it with Python2 like this


Similarly, if you want to run it with Python3, that's it.


Remove Parameter -2/-3

Adding parameter -2/-3 to each run is still 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

#! Python2


#! Python3

Indicates that the code file is run with Python2 or Python3 interpretation, respectively. This way, your commands can be simplified when you run them to


Using PIP

When Python2 and Python3 are present on Windows, their corresponding Pip is called Pip.exe, so it is not possible to install the package directly using the PIP Install command. 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 the software is installed for Python3, then the command resembles

Py-3-m pip install XXXX

#! 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 beginning of the file should resemble:

#! python2# coding: utf-8
Provides a solution under Windows:
First the python2 pip, its default path is C:\Python27\Scripts

See no, it is afraid you can not find, you give yourself up 3 names, whichever you use.

Then install the Python3 pip, whose default path is C:\users\***\appdata\local\programs\python\python35-32\scripts

It is also a 3 name.

Then you add these two paths to the environment variables and you can use them happily.
PIP2 Install ... (Python2)
PIP3 Install ... (Python3)
Install the library separately. In order to answer this question, purposely ran to a CentOS 6.5 installed a Python3 (without the Ubuntu environment), and then installed a PIP, through LN to create a connection, alias create aliases These operations, prove Python2 and Python3 Can still be perfect coexistence.
The main problem is not to be able to coexist, but in the default pip Install command to Python3 installation of the procedure itself is wrong, the following is my solution:

The environment has been preceded by Python and Pip,
# python --version:Python 2.7.9# pip --versionpip 8.1.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
Ibid., with virtualenv
pip:www.pip-installer.orgvirtualenv:http://www.virtualenv.orgvirtualenvwrapper: Virtualenv is Lib-level isolation, and if you need to isolate the Python interpreter, you can directly use the
Yyuu/pyenv GitHub Recommended for Yyuu/pyenv GitHub , so that you can install as many Python versions as possible without modifying the python that comes with the system, and that the versions are isolated from one another and are easy to manage in multiple versions. To use Virtualenv is the kingly.
In addition according to / http cn/quantal/all/python3-pip/filelist Look here, Python3-pip is supposed to be pip-3.2 and the like. Use Dpkg-l Python3-pip to take a look at the command full path.
  • 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: 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.