为什么Pip会忽略冲突的依赖关系?

时间:2013-01-21 18:44:05

标签: python python-2.7 pip python-2.x

如果我创建一个虚拟包 - 这是/tmp/example_package/setup.py(注意要求):

from distutils.core import setup

setup(name='my_project',
      description="Just a test project",
      version="1.0",
      py_modules=['sample'],
      install_requires=['requests > 0.12'])

这是/tmp/example_package/sample.py:

import requests

def get_example():
    return requests.get("http://www.example.com")

现在,我创建了一个virtualenv:

$ virtualenv /tmp/foobar --distribute -p python2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /tmp/foobar/bin/python2.7
Also creating executable in /tmp/foobar/bin/python
Installing distribute.................................................................................................................................................................................................done.
Installing pip................done.
$ source /tmp/foobar/bin/activate

我创建了一个需求冲突的requirements.pip

# this requires requests > 0.12:
file:///tmp/example_package

# but this conflicts:
requests==0.9.0

Pip愉快地安装了这个:

$ pip install -r requirements.pip                                                                                                                                                                       [18:40:10]
Unpacking ./example_package
  Running setup.py egg_info for package from file:///tmp/example_package

Downloading/unpacking requests==0.9.0 (from -r requirements.pip (line 3))
  Downloading requests-0.9.0.tar.gz (55Kb): 55Kb downloaded
  Running setup.py egg_info for package requests

Downloading/unpacking certifi>=0.0.4 (from requests==0.9.0->-r requirements.pip (line 3))
  Downloading certifi-0.0.8.tar.gz (118Kb): 118Kb downloaded
  Running setup.py egg_info for package certifi

Installing collected packages: requests, my-project, certifi
  Running setup.py install for requests

  Running setup.py install for my-project

  Running setup.py install for certifi

Successfully installed requests my-project certifi
Cleaning up...

为什么Pip允许这个?我的example_package无效,因为无法满足其要求。

2 个答案:

答案 0 :(得分:3)

这是Pip的限制。需求文件胜过包的要求。见https://github.com/pypa/pip/issues/775#issuecomment-12748095

答案 1 :(得分:2)

看一下pip源,它似乎应该递归地将所有需求添加到一个大的RequirementSet ...然后崩溃并出现'重复需求'异常......

嗯..你确定你的setup.py是正确的吗?

Distutils有requires个关键字但不是install_requireshttp://docs.python.org/2/distutils/setupscript.html#relationships-between-distributions-and-packages

提到这个的答案:
https://stackoverflow.com/a/10686196/202168
https://stackoverflow.com/a/13468644/202168