How to use pip with Python 3.x alongside Python 2.x

PythonPython 3.xPython 2.7Pip

Python Problem Overview


I installed Python 3.x (besides Python 2.x on Ubuntu) and slowly started to pair modules I use in Python 2.x.

So I wonder, what approach should I take to make my life easy by using pip for both Python 2.x and Python 3.x?

Python Solutions


Solution 1 - Python

The approach you should take is to install pip for Python 3.2.

You do this in the following way:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3.2 get-pip.py

Then, you can install things for Python 3.2 with pip-3.2, and install things for Python 2-7 with pip-2.7. The pip command will end up pointing to one of these, but I'm not sure which, so you will have to check.

Solution 2 - Python

What you can also do is to use apt-get:

apt-get install python3-pip

In my experience this works pretty fluent too, plus you get all the benefits from apt-get.

Solution 3 - Python

First, install Python 3 pip using:

sudo apt-get install python3-pip

Then, to use Python 3 pip use:

pip3 install <module-name>

For Python 2 pip use:

pip install <module-name>

Solution 4 - Python

The shortest way:

python3 -m pip install package
python -m pip install package

Solution 5 - Python

If you don't want to have to specify the version every time you use pip:

Install pip:

$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

and export the path:

$ export PATH=/Library/Frameworks/Python.framework/Versions/<version number>/bin:$PATH

Solution 6 - Python

In Windows, first installed Python 3.7 and then Python 2.7. Then, use command prompt:

> pip install python2-module-name > > pip3 install python3-module-name

That's all

Solution 7 - Python

This worked for me on OS X: (I say this because sometimes is a pain that mac has "its own" version of every open source tool, and you cannot remove it because "its improvements" make it unique for other apple stuff to work, and if you remove it things start falling appart)

I followed the steps provided by @Lennart Regebro to get pip for python 3, nevertheless pip for python 2 was still first on the path, so... what I did is to create a symbolic link to python 3 inside /usr/bin (in deed I did the same to have my 2 pythons running in peace):

ln -s /Library/Frameworks/Python.framework/Versions/3.4/bin/pip /usr/bin/pip3

Notice that I added a 3 at the end, so basically what you have to do is to use pip3 instead of just pip.

The post is old but I hope this helps someone someday. this should theoretically work for any LINUX system.

Solution 8 - Python

On Suse Linux 13.2, pip calls python3, but pip2 is available to use the older python version.

Solution 9 - Python

Please note that on msys2 I've found these commands to be helpful:

$ pacman -S python3-pip
$ pip3 install --upgrade pip
$ pip3 install --user package_name

Solution 10 - Python

  1. To use pip for a Python 2.x environment, use this command:

    py -2 -m pip install -r requirements.txt
    
  2. To use pip for Python 3.x environment, use this command:

    py -3 -m pip install -r requirements.txt
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionthetaView Question on Stackoverflow
Solution 1 - PythonLennart RegebroView Answer on Stackoverflow
Solution 2 - PythonErik PragtView Answer on Stackoverflow
Solution 3 - Pythonaadarsh karumathilView Answer on Stackoverflow
Solution 4 - PythonfiveelementsView Answer on Stackoverflow
Solution 5 - PythontldrView Answer on Stackoverflow
Solution 6 - PythonKardi TeknomoView Answer on Stackoverflow
Solution 7 - PythonOrdielView Answer on Stackoverflow
Solution 8 - PythonkarstenView Answer on Stackoverflow
Solution 9 - Pythonuser8128167View Answer on Stackoverflow
Solution 10 - PythonAnurag DawareView Answer on Stackoverflow