Y a-t-il un moyen de faire en sorte que pip
fonctionne bien avec plusieurs versions de Python ? Par exemple, je veux utiliser pip
pour installer explicitement des choses soit sur mon site 2.5, soit sur mon site 2.6.
Par exemple, avec easy_install
, j'utilise easy_install-2.{5,6}
.
Et, oui, je connais virtualenv, et non, ce n'est pas une solution à ce problème particulier.
La [recommandation actuelle][0] est d'utiliser python -m pip
, où python
est la version de Python que vous souhaitez utiliser. C'est la recommandation parce qu'elle fonctionne avec toutes les versions de Python, et dans toutes les formes de virtualenv. Par exemple :
# 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
[0] : https://packaging.python.org/guides/installing-using-pip-and-virtualenv/
Réponse précédente, laissée pour la postérité :
Depuis la version 0.8, Pip supporte pip-{version}
. Vous pouvez l'utiliser de la même manière que easy_install-{version}
:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
EDIT : pip a changé son schéma pour utiliser pipVERSION
au lieu de pip-VERSION
dans la version 1.5. Vous devriez utiliser ce qui suit si vous avez pip >= 1.5
:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Consultez https://github.com/pypa/pip/pull/1053 pour plus de détails
Références :
/path/to/python2.{5,6} /path/to/pip install PackageName
ne fonctionne pas ?
Pour que cela fonctionne sur une version de python qui n'a pas pip déjà installé, vous devez télécharger pip et faire python*version* setup.py install
. Par exemple python3.3 setup.py install
. Cela résout l'erreur d'importation dans les commentaires. (Comme suggéré par @hbdgaf)
Apparemment, il y a plusieurs versions de easy_install
et de pip
. Cela semble être un grand désordre. Bref, voici ce que j'ai fait pour installer Django pour Python 2.7 sur 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
>>>