有没有办法让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 3设置期间安装pip模块,则可以通过Python启动器py.exe使用给定的Python版本执行pip模块。
py -3 -m pip install packagename
py -2 -m pip install packagename
你可以更具体地请求Python的精确子版本:
py -3.6 -m pip install packagename
要获得通过启动程序可用的所有已安装Python版本的列表,请运行:
py --list
或者,您可以直接启动所需的Python可执行文件:
C:/path/to/specific/python.exe -m pip install packagename
其他回答
目前建议使用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
上下文:Archlinux
行动: 安装python2-pip: sudo pacman -S python2-pip
你现在有了pip2.7: Sudo pip2.7安装boto
测试(在我的情况下,我需要'boto'): 执行如下命令:
python2
import boto
成功:没有错误。
退出:按Ctrl + D
pip debug命令提供了一些用于调试的有用信息。它在第一行(警告之后)显示了附加的python解释器的位置。
$ pip debug
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 21.2.4 from /data/akshay/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
sys.version: 3.9.12 (main, Apr 5 2022, 06:56:58)
sys.executable: /data/akshay/anaconda3/bin/python
具体到windows: \path\to\python.exe -m pip install PackageName works
您可以使用以下命令之一:
pip2 install SomePackage
pip3 install SomePackage
python2 -m pip install SomePackage
python3 -m pip install SomePackage
当然,还要确保安装了正确的pip版本
sudo apt-get install python-pip
sudo apt-get install python3-pip
我自己没有使用过这些命令,但是上面的一些回答建议使用它们来指定你想使用的python版本
pip-2.7 install SomePackage
python-3.6 -m pip install SomePackage