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

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

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


当前回答

搅拌机:

/usr/bin $ python3.7 -m pip install irc

其他回答

搅拌机:

/usr/bin $ python3.7 -m pip install irc

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

Pip {version}和运行命令

示例:用于python 3.10

pip3.10 pip3.10列表

pip3.10

适用于Python 3.7

pip3.7 pip3.7列表

如果您有多个版本以及多个架构(32位,64位),您将需要在版本的末尾添加-32或-64。

对于windows,进入cmd并输入py——list,它将生成您已安装的版本。列表如下所示:

Installed Pythons found by py Launcher for Windows
 -3.7-64 *
 -3.7-32
 -3.6-32

以完整命令为例:

py -3.6-32 -m pip install (package)

如果你想更深入地了解,在特定版本的python上安装特定版本的包,请在包后使用==(version)。举个例子,

py -3.6-32 -m pip install opencv-python==4.1.0.25

上下文:Archlinux

行动: 安装python2-pip: sudo pacman -S python2-pip

你现在有了pip2.7: Sudo pip2.7安装boto

测试(在我的情况下,我需要'boto'): 执行如下命令:

python2
import boto

成功:没有错误。

退出:按Ctrl + D

另一种可能的方法是使用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

这里有一种可能的方法。