有没有办法让pip在多个版本的Python中都能很好地运行?例如,我想使用pip显式地将东西安装到我的站点2.5安装或站点2.6安装中。

例如,对于easy_install,我使用easy_install-2.{5,6}。

是的,我知道virtualenv,不,它不是这个特殊问题的解决方案。


当前回答

PIP也是一个python包。因此,将模块安装到特定python版本的最简单方法如下所示

 python2.7 /usr/bin/pip install foo

or

python2.7 -m pip install foo

其他回答

要使用多个版本的pip,只需输入

Pip {version}和运行命令

示例:用于python 3.10

pip3.10 pip3.10列表

pip3.10

适用于Python 3.7

pip3.7 pip3.7列表

另一种可能的方法是使用conda和pip。有时你可能只想使用其中的一个,但如果你真的需要设置一个特定版本的python,我会将两者结合起来。

I create a starting conda enviroment with the python I want. As in here https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html. Alternatively you could set up the whole enviroment just using conda. conda create -n myenv python=3.6.4 Then activate your enviroment with the python you like. This command could change depending on the OS. source activae myenv Now you have your python active then you could continue using conda but if you need/want to use pip: python -m pip -r requirements.txt

这里有一种可能的方法。

对于python 3和Windows操作系统,我总是使用这种语法在不同版本上安装包:

首先,我总是使用Git Bash命令提示符。

这里有一个安装urllib包的例子。

默认Python版本:(普通pip命令)

pip install urllib3

对于其他版本

py -3.8 -m pip install urllib3

python的Py => -3.8 =>的版本(我使用3.8.7版本),但如果你使用3.7.7版本,它将是“-3.7” -m: just because or for modify PIP install urllib3: PIP正常命令

我自己最近也遇到了这个问题,发现在我的Linux系统上,Python 2也没有得到正确的Python 3的pip。

首先,你必须确保已经为你的python版本安装了pip:

对于Python 2:

sudo apt-get install python-pip

对于Python 3:

sudo apt-get install python3-pip

然后,要安装一个版本的Python或其他版本的包,只需在Python 2中使用以下命令:

pip install <package>

或Python 3:

pip3 install <package>

例如,您可以转到C:\Python2.7\Scripts,然后从该路径运行cmd。然后你可以运行pip2.7安装你的包…

这将为该版本的Python安装包。