Is there any way to make pip
play well with multiple versions of Python? For example, I want to use pip
to explicitly install things to either my site 2.5 installation or my site 2.6 installation.
For example, with easy_install
, I use easy_install-2.{5,6}
.
And, yes — I know about virtualenv, and no — it's not a solution to this particular problem.
In Windows, you can execute the pip module by mentioning the python version ( You need to ensure that the launcher is on your path )
py -3.4 -m pip install pyfora
py -2.7 -m pip install pyfora
Alternatively, you can call the desired python executable directly like this:
/path/to/python.exe -m pip install pyfora
Other answers show how to use pip with both 2.X and 3.X Python, but does not show how to handle the case of multiple Python distributions (eg. original Python and Anaconda Python).
I have a total of 3 Python versions: original Python 2.7 and Python 3.5 and Anaconda Python 3.5.
Here is how I install a package into:
Original Python 3.5:
Original Python 2.7:
Anaconda Python 3.5:
or
Simpler, as Anaconda overrides original Python binaries in user environment.
Of course, installing in anaconda should be done with
conda
command, this is just an example.Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:
or
I ran into this issue myself recently and found that I wasn't getting the right pip for Python 3, on my Linux system that also has Python 2.
First you must ensure that you have installed pip for your python version:
For Python 2:
For Python 3:
Then to install packages for one version of Python or the other, simply use the following for Python 2:
or for Python 3:
The current recommendation is to use
python -m pip
, wherepython
is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:Previous answer, left for posterity:
Since version 0.8, Pip supports
pip-{version}
. You can use it the same aseasy_install-{version}
:EDIT: pip changed its schema to use
pipVERSION
instead ofpip-VERSION
in version 1.5. You should use the following if you havepip >= 1.5
:Check https://github.com/pypa/pip/pull/1053 for more details
References:
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the
-m
switch to run the appropriate copy ofpip
:(appropriately versioned pip commands may also be available)
On Windows, use the
py
Python launcher in combination with the-m
switch:if you get an error for
py -3.4
then try:/path/to/python2.{5,6} /path/to/pip install PackageName
doesn't work?For this to work on any python version that doesn't have pip already installed you need to download pip and do
python*version* setup.py install
. For examplepython3.3 setup.py install
. This resolves the import error in the comments. (As suggested by @hbdgaf)