6

ダミーパッケージを作成する場合-ここに/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...

なぜピップはこれを許可するのですか?要件example_packageが満たされていないため、動作しません。

4

2 に答える 2

3

これは Pip の制限です。要件ファイルは、パッケージの要件よりも優先されます。https://github.com/pypa/pip/issues/775#issuecomment-12748095を参照してください

于 2013-01-29T14:27:12.493 に答える
2

Looking at the pip source it seems like it should recursively add all the requirements to one big RequirementSet... and then crash out with a 'Duplicate requirement' exception...

Hmm.. are you sure your setup.py is correct?

Distutils has a requires keyword but not install_requires: http://docs.python.org/2/distutils/setupscript.html#relationships-between-distributions-and-packages

SO answers which reference this:
https://stackoverflow.com/a/10686196/202168
https://stackoverflow.com/a/13468644/202168

于 2013-01-22T12:47:58.910 に答える