Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install pip for a specific python version

I have my deployment system running CentOS 6.

It has by default python 2.6.6 installed. So, "which python" gives me /usr/bin/python (which is 2.6.6)

I later installed python3.5, which is invoked as python3 ("which python3" gives me /usr/local/bin/python3)

Using pip, I need to install a few packages that are specific to python3. So I did pip install using:- "sudo yum install python-pip" So "which pip" is /usr/bin/pip.

Now whenever I do any "pip install", it just installs it for 2.6.6. :-(

It is clear that pip installation got tied to python 2.6.6 and invoking pip later, only installs packages for 2.6.6.

How can I get around this issue?

like image 704
Sam Avatar asked Feb 21 '17 15:02

Sam


1 Answers

If pip isn’t already installed, then first try to bootstrap it from the standard library:

$ python3.5 -m ensurepip --default-pip  

If that still doesn’t allow you to run pip:

  • Securely Download get-pip.py.
  • Run sudo python3.5 get-pip.py.

Now you can use pip3 to install packages for python3.5. For example, try:

$ sudo pip3 install ipython  # isntall IPython for python3.5

Alternatively, as long as the corresponding pip has been installed, you can use pip for a specific Python version like this:

$ python3.5 -m pip install SomePackage  # specifically Python 3.5

References:

  • Ensure you can run pip from the command line
  • work with multiple versions of Python installed in parallel?
like image 186
Wong Avatar answered Sep 17 '22 15:09

Wong