有没有办法让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,不,它不是这个特殊问题的解决方案。
当前回答
显然,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
>>>
其他回答
如果你同时安装了python3.6和python3.7,并且希望在默认情况下对python3.7使用pip,那么你应该这样做:
首先,确保为python3.7安装了pip
python3.7 -m pip install -U pip
现在pip3.7必须可用,因此我们编辑.bashrc
nano ~/.bashrc
向它添加下面的行
alias pip=pip3.7
为了使更改生效,在shell中输入:
source ~/.bashrc
现在如果你输入:
pip --version
你应该得到:
PIP 20.1.1 from /usr/local/lib/python3.7/dist-packages/ PIP (python 3.7)
这意味着,如果你使用,例如:
pip install <package>
它将为python3.7安装<package>
网址: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
它在windows中是这样工作的:
我将python文件的名称python.py和pythonw.exe更改为python3.py pythonw3.py 然后我在提示符中运行这个命令: Python3 -m PIP安装包
具体到windows: \path\to\python.exe -m pip install PackageName works
对于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正常命令