有没有办法让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,不,它不是这个特殊问题的解决方案。
当前回答
对于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正常命令
其他回答
其他答案展示了如何将pip与两者一起使用。X和3。X Python,但没有说明如何处理多个Python发行版的情况(例如。原始Python和Anaconda Python)。
我总共有3个Python版本:原始Python 2.7和Python 3.5和Anaconda Python 3.5。
下面是我如何安装一个包到:
原始Python 3.5: /usr/bin/python3 -m PIP安装python-daemon 原始Python 2.7: /usr/bin/python -m PIP安装python-daemon 蟒蛇3.5: Python3 -m PIP安装python-daemon 或 Pip3安装python-daemon 更简单,因为Anaconda在用户环境中覆盖原始的Python二进制文件。 当然,安装在anaconda应该用conda命令来完成,这只是一个例子。
另外,确保为特定的python安装了pip。您可能需要手动安装pip。这适用于Ubuntu 16.04:
sudo apt-get install python-pip
or
sudo apt-get install python3-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>
如果您有多个版本以及多个架构(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
网址: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
在Linux、Mac OS X和其他POSIX系统上,使用带版本控制的Python命令和-m开关来运行pip的适当副本:
python2.7 -m pip install SomePackage
python3.4 -m pip install SomePackage
(也可以使用版本适当的PIP命令)
在Windows上,将py Python启动器与-m开关结合使用:
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3.4 -m pip install SomePackage # specifically Python 3.4
如果py -3.4有错误,那么试试:
pip install SomePackage