如果我创建一个虚拟包 -- 这是 /tmp/example_package/setup.py 文件(注意要求):
现在,我创建了一个虚拟环境:
我创建了一个 requirements.pip 文件,其中包含有冲突的依赖关系:
Pip乐意地安装了这个:
为什么Pip会允许这种情况发生呢?我的
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 /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
不能工作,因为它的要求没有被满足。
install_requires
,pip在其他情况下会忽略我的依赖关系。 - Wilfred Hughesinstall_requires
似乎有些可疑 https://bitbucket.org/carljm/python-distutils/src/48c42eeaee4410d76675b637bcd401b8919ff19a/core.py?at=default#cl-44 和 http://svn.python.org/view/sandbox/trunk/setuptools/setuptools/dist.py?view=log (line 170) - Anentropicinstall_requires
应该没问题,因为 Pip 使用 setuptools 来进行安装 https://dev59.com/JXRC5IYBdhLWcg3wOeaB#370062 ... 另外,我并不是第一个注意到这一点的人,但当你深入了解 Python 的打包机制时,你会发现它真的是一团糟! - Anentropic