Dealing with multiple Python versions and PIP?
Solution 1:
The current recommendation is to use python -m pip
, where python
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:
# The system default python:
$ python -m pip install fish
# A virtualenv's python:
$ .env/bin/python -m pip install fish
# A specific version of python:
$ python-3.6 -m pip install fish
Previous answer, left for posterity:
Since version 0.8, Pip supports pip-{version}
. You can use it the same as easy_install-{version}
:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
EDIT: pip changed its schema to use pipVERSION
instead of pip-VERSION
in version 1.5. You should use the following if you have pip >= 1.5
:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Check https://github.com/pypa/pip/pull/1053 for more details
References:
- https://github.com/pypa/pip/issues/200
- http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4
Solution 2:
On Windows, you can execute the pip module using a given Python version through the Python launcher, py.exe
, if you chose to install it during Python 3 setup.
py -3 -m pip install packagename
py -2 -m pip install packagename
You can be even more specific and request an exact sub-version of Python:
py -3.6 -m pip install packagename
To get a list of all installed Python versions available through the launcher, run:
py --list
Alternatively, you can launch the desired Python executable directly:
C:/path/to/specific/python.exe -m pip install packagename
Solution 3:
/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 example python3.3 setup.py install
. This resolves the import error in the comments. (As suggested by @hbdgaf)
Solution 4:
I had python 2.6 installed by default (Amazon EC2 AMI), but needed python2.7 plus some external packages for my application. Assuming you already installed python2.7 alongside with default python (2.6 in my case). Here is how to install pip and packages for non-default python2.7
Install pip for your python version:
curl -O https://bootstrap.pypa.io/get-pip.py
python27 get-pip.py
Use specific pip version to install packages:
pip2.7 install mysql-connector-python --allow-external mysql-connector-python
Solution 5:
It worked for me in windows this way:
-
I changed the name of python files python.py and pythonw.exe to python3.py pythonw3.py
-
Then I just ran this command in the prompt:
python3 -m pip install package