Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run pip of different version of python using 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.

like image 977
Alfred Huang Avatar asked Jan 15 '16 01:01

Alfred Huang


People also ask

How do I install a specific version of a Python package pip?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .

How do I run a different version of Python?

The default Python interpreter is referenced on Windows using the command py. Using the Command Prompt, you can use the -V option to print out the version. You can also specify the version of Python you'd like to run. For Windows, you can just provide an option like -2.7 to run version 2.7.

Can I run 2 versions of Python?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.


2 Answers

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
like image 140
Alfred Huang Avatar answered Oct 06 '22 09:10

Alfred Huang


How about using pyenv?

You can switch the version.

$ pyenv install 2.7.X
$ pyenv install 3.5.X
$ pyenv local 2.7.X
$ pyenv global 3.5.X
like image 36
masudak Avatar answered Oct 06 '22 08:10

masudak