The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC E Schuberts Piano Sonata D 784 in A

--

Chapters
00:00 Question
00:34 Accepted answer (Score 203)
01:09 Answer 2 (Score 59)
01:28 Answer 3 (Score 54)
01:55 Answer 4 (Score 28)
02:08 Thank you

--

Full question
https://stackoverflow.com/questions/1126...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #python3x #python27 #pip

#avk47



ACCEPTED ANSWER

Score 206


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.




ANSWER 2

Score 60


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.




ANSWER 3

Score 56


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>



ANSWER 4

Score 15


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