gpt4 book ai didi

python - 为什么 Pip 会忽略冲突的依赖项?

转载 作者:太空狗 更新时间:2023-10-30 01:09:18 26 4
gpt4 key购买 nike

如果我创建一个虚拟包——这里是/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 将无法运行,因为它的要求没有得到满足。

最佳答案

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

关于python - 为什么 Pip 会忽略冲突的依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14445169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com