有没有办法让pip在多个版本的Python中都能很好地运行?例如,我想使用pip显式地将东西安装到我的站点2.5安装或站点2.6安装中。
例如,对于easy_install,我使用easy_install-2.{5,6}。
是的,我知道virtualenv,不,它不是这个特殊问题的解决方案。
有没有办法让pip在多个版本的Python中都能很好地运行?例如,我想使用pip显式地将东西安装到我的站点2.5安装或站点2.6安装中。
例如,对于easy_install,我使用easy_install-2.{5,6}。
是的,我知道virtualenv,不,它不是这个特殊问题的解决方案。
当前回答
它在windows中是这样工作的:
我将python文件的名称python.py和pythonw.exe更改为python3.py pythonw3.py 然后我在提示符中运行这个命令: Python3 -m PIP安装包
其他回答
网址:https://docs.python.org/3/installing/
下面是如何为同时安装的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
在Windows上,将py Python启动器与-m开关结合使用:
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
/ / python2 /路径。{5,6} /path/to/pip install PackageName不正常?
为了在任何没有安装pip的python版本上工作,你需要下载pip并执行python*version* setup.py install。例如python3.3 setup.py install。这解决了注释中的导入错误。(@hbdgaf建议)
它在windows中是这样工作的:
我将python文件的名称python.py和pythonw.exe更改为python3.py pythonw3.py 然后我在提示符中运行这个命令: Python3 -m PIP安装包
目前建议使用python -m pip,其中python是您想使用的python版本。这是推荐的,因为它适用于所有版本的Python和所有形式的virtualenv。例如:
# 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.8版本开始,Pip支持Pip -{version}。你可以像easy_install-{version}一样使用它:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
编辑:在1.5版中,pip将其模式更改为使用pipVERSION而不是pip- version。如果你的pip >= 1.5,你应该使用以下命令:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
更多详情请登录https://github.com/pypa/pip/pull/1053
引用:
https://github.com/pypa/pip/issues/200 http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4 https://pip.pypa.io/en/stable/news/ v0-8或 https://web.archive.org/web/20140310013920/http://www.pip-installer.org:80/docs/pip/en/0.8.3/news.html#id4
显然,easy_install和pip有多个版本。看起来很乱。不管怎样,这是我在Ubuntu 12.10上安装Django for Python 2.7的方法:
$ 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
>>>