Search code examples
pythonpython-3.xpip

How to run pip from different versions of python using the python command?


I'm now currently using Python on Ubuntu 15.10.

But in my OS, I have many different python versions installed:

  • Python (2.7.9)
  • Python3 (3.4.3)
  • Python3.5
  • PyPy

So, it got messy with the versions of the packages in different environments. For example, if I run:

pip3 install django

But in fact, I cannot import django inside python3.5.

Is there any efficient way to call the correct version of pip?

Note:
Don't suggest that I use virtualenv, I know about it and am seeking another solution.


Solution

  • Finally I found the solution myself, see the Docs:

    https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel

    Just call:

    pythonXX -m pip install SomePackage
    

    That would work separately for each version of installed python.

    Also, according to the docs, if we want to do the same thing in windows, the command is a bit different:

    py -2   -m pip install SomePackage  # default Python 2
    py -2.7 -m pip install SomePackage  # specifically Python 2.7
    py -3   -m pip install SomePackage  # default Python 3
    py -3.4 -m pip install SomePackage  # specifically Python 3.4