15

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?

Sam
  • 323
  • 2
  • 3
  • 8
  • 1
    Possible duplicate of [pip: dealing with multiple Python versions?](http://stackoverflow.com/questions/2812520/pip-dealing-with-multiple-python-versions) – Leon Z. Feb 21 '17 at 15:27
  • 1
    Check if you have a program `pip3` installed. This downloads python3 versions of packages. – Connor Harris Feb 21 '17 at 15:33
  • I'd recommend looking into [virtual environments](https://virtualenv.pypa.io/en/stable/) – Anfernee Feb 21 '17 at 16:19
  • Each `pip` is tied to its Python binary. So installation packages using one pip instance will not install packages for other Python versions. – Harald Nordgren Feb 21 '17 at 22:59
  • How did you your install python3.5? – Harald Nordgren Feb 21 '17 at 22:59
  • I disagree it is a duplicate. A new version of python has installed. This version does not have a pip yet. In the possible duplicate pip for the new python version is assumed to be installed. – fabiob Jan 11 '19 at 10:09

4 Answers4

17

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:

Wong
  • 171
  • 1
  • 5
2

I have python 3.6 and 3.8 on my Ubuntu 18.04 WSL machine. Running

sudo apt-get install python3-pip

pip3 install my_package_name

kept installing packages into Python 3.6 dist directories. The only way that I could install packages for Python 3.8 was:

python3.8 -m pip install my_package_name

That installed appropriate package into the Python 3.8 dist package directory so that when I ran my code with python3.8, the required package was available.

IvanD
  • 7,971
  • 4
  • 35
  • 33
1

Example of how to install pip for a specific python version

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/opt/local/bin/python2.7 get-pip.py

Script is from official doc: https://pip.pypa.io/en/stable/installing/

Sophia Feng
  • 993
  • 11
  • 16
-3

On Ubuntu 18.04.1 LTS I wanted to install pip for my second python version (python3) and the following command did the trick for me:

$ sudo apt install python3-pip
  • 3
    In my case, this was not helpful since it still downloaded python3.6 even though I already had 3.7 installed. – Bram Vanroy Nov 30 '19 at 19:49