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

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

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


当前回答

它在windows中是这样工作的:

我将python文件的名称python.py和pythonw.exe更改为python3.py pythonw3.py 然后我在提示符中运行这个命令: Python3 -m PIP安装包

其他回答

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

Pip {version}和运行命令

示例:用于python 3.10

pip3.10 pip3.10列表

pip3.10

适用于Python 3.7

pip3.7 pip3.7列表

我默认安装了python 2.6 (Amazon EC2 AMI),但我的应用程序需要python2.7加上一些外部包。假设您已经安装了python2.7和默认的python(在我的例子中是2.6)。下面是如何为非默认的python2.7安装pip和包

为你的python版本安装pip:

curl -O https://bootstrap.pypa.io/get-pip.py
python27 get-pip.py

使用指定的pip版本安装软件包:

pip2.7 install mysql-connector-python --allow-external mysql-connector-python

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

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

具体到windows: \path\to\python.exe -m pip install PackageName works

显然,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
>>>