Pip different python versions

Dealing with multiple Python versions and PIP?

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.

@JinSnow It should, provided pip3.x actually manages the python version that you want to install packages to (perhaps run pip3.x -V to see). Or use @Hugo’s solution to have better control over lots of python versions.

28 Answers 28

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- . You can use it the same as easy_install- :

$ 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 

Doesn’t work. Although the latest version of pip installed a pip-2.6 script, it didn’t bother to install a pip-2.5 script.

Читайте также:  Php test zip file

You need to update your python2.5 pip version. It only creates pip- under the python you are using pip.

This is incorrect. I’m running pip 1.2.1 with Python2.7 on Ubuntu, and there are no alternative pip versions.

@rodling: probably you didn’t installed pip via pip / easy_install or get-pip.py or you don’t have python2.7. if you have python2.7, try: pip install —upgrade pip and you should have pip and pip-2.7

@J.C.Rocamonde: the program pip gets picked based on the environment variable $PATH. If you want to change what is the «default» pip program, reorder the $PATH environment variable. Search for something like «path environment variable linux» for more details on $PATH.

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:

Alternatively, you can launch the desired Python executable directly:

C:/path/to/specific/python.exe -m pip install packagename 

Thank you, this worked for me! Can’t believe how difficult it was. (None of these or variations python-3.7 -m pip install or python-3.7 -m pip install or python3.7 -m pip install worked for me. )

py -3.6 -m pip install packagename does not work. I get «Unknown option: -3» Nor do the options jeppoo1 tried.

/path/to/python2. /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)

For this to work on say python 3 you need to download pip and do «python3 setup.py install». Personally I find this solution to be not very nice. For a start I didn’t even know the pip command wasn’t a binary. This isn’t a criticism of @bwinton, I’m just surprised there isn’t a better way to do this.

I’m baffled that the problem with the importerror got more upticks than the solution to the same one comment above it.

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 

great worked for me for python 3.4 with following: python3 get-pip.py and later using pip command with pip34 install example

Got Could not find a version that satisfies the requirement pip (from versions: ) No matching distribution found for pip when I tried python2.6 get-pip.py

It worked for me in windows this way:

  1. I changed the name of python files python.py and pythonw.exe to python3.py pythonw3.py
  2. Then I just ran this command in the prompt: python3 -m pip install package

Just for anyone else figuring out how to install packages in python3 using pip on mac, this command is how you install packages. I spent hours searching and I’ve finally found it!

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:

/usr/bin/python3 -m pip install python-daemon 
/usr/bin/python -m pip install python-daemon 
python3 -m pip install python-daemon 
pip3 install python-daemon 

Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:

sudo apt-get install python-pip 
sudo apt-get install python3-pip 

The advice regarding Anaconda here is not accurate. it doesn’t «override» anything. The fact that it is picking up the Anaconda version as default on your system is simply a side-effect of your specific configuration, how you installed each interpreter, and your environment’s path ordering. those will vary for others.

You sir, are the man. Of all the totally useless explanations surrounding this issue, this is the only one that has made sense to me. Time to alias these commands and get on with my life! THANK YOU.

This is pretty confusing on ubuntu the python3 pip installs as pip command and python 3.6 as python3. python2.7 installs as python command and pip for it installs as pip2.

Here is how to install packages for various versions that are installed at the same time linux, mac, posix:

python2 -m pip install SomePackage # default Python 2 python2.7 -m pip install SomePackage # specifically Python 2.7 python3 -m pip install SomePackage # default Python 3 python3.4 -m pip install SomePackage # specifically Python 3.4 python3.5 -m pip install SomePackage # specifically Python 3.5 python3.6 -m pip install SomePackage # specifically Python 3.6 

On Windows, use the py Python launcher in combination with the -m switch:

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 

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:

sudo apt-get install python-pip 
sudo apt-get install python3-pip 

Then to install packages for one version of Python or the other, simply use the following for Python 2:

pip is also a python package. So the easiest way to install modules to a specific python version would be below

 python2.7 /usr/bin/pip install foo 
python2.7 -m pip install foo 

So apparently there are multiple versions of easy_install and pip . It seems to be a big mess. Anyway, this is what I did to install Django for Python 2.7 on Ubuntu 12.10:

$ sudo easy_install-2.7 pip Searching for pip Best match: pip 1.1 Adding pip 1.1 to easy-install.pth file Installing pip-2.7 script to /usr/local/bin Using /usr/lib/python2.7/dist-packages Processing dependencies for pip Finished processing dependencies for pip $ sudo pip-2.7 install django Downloading/unpacking django Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded Running setup.py egg_info for package django warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.py[co]' found under directory '*' Installing collected packages: django Running setup.py install for django changing mode of build/scripts-2.7/django-admin.py from 644 to 755 warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*.py[co]' found under directory '*' changing mode of /usr/local/bin/django-admin.py to 755 Successfully installed django Cleaning up. $ python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> 

Источник

How to install pip associated to different versions of Python

Currently, I am running two versions of python on Mac. The native one (2.7.10) ( /usr/bin/python ), and another one, which has been downloaded via home-brew ( 2.7.14 ). I want to download two versions of pip and download packages depending on the python version I want to use. Is this possible?

Sure, just take a look at virtualenv . It allows you to maintain multiple python environments and their packages in parallel. With the -p argument you can select the interpreter to be used for a particular environment.

2 Answers 2

Start by checking your available Python interpreters on your command line:

[root@server ~]# ls /usr/bin/ | grep python python2 -> python2.6 python2.6 python3 -> python3.4 python3.4 

Then download and run this file using each interpreter

[root@server ~]# python2.6 get-pip.py [root@server ~]# python3.4 get-pip.py 

Then once both Python interpreters have the pip module installed, you can install packages to your specific Python interpreters using the following commands:

[root@server ~]# python2.6 -m pip install [root@server ~]# python3.4 -m pip install

It’s worth mentioning (for Windows Users), once you have multiple versions of Python installed, you can easily manage packages for each specific version by calling pip. from a cmd window.

for example, I have Python 2.7, 3.6 and 3.7 currently installed, and I can manage my packages for each installation using pip2.7, pip3.6 and pip3.7 respectively .

On Windows 10, $ pip3.7 install works for me — haven’t tested it with venv instances yet though

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.20.43540

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Оцените статью