为什么Pip会忽略具有嵌套依赖项的已配置存储库? [英] Why does Pip disregard configured repository with nested dependencies?
问题描述
让我们说我在Linux机器上有一个完全空的Python + Pip + R(pip 19.3.1)环境,我想用pip安装软件包rpy2
.由于我位于公司防火墙的后面,因此我将pip配置为使用私有存储库.
Let us say I have a completely empty Python+Pip+R (pip 19.3.1) environment on a Linux machine and I want to install the package rpy2
with pip. Since I am behind a corporate firewall I configure pip to use a private repository.
[global]
index-url = http://private.com/artifactory/api/pypi/PyPI/simple
trusted-host = private.com
现在我执行pip install rpy2
,我将获得以下错误:
Now I execute pip install rpy2
and I will get back the following error:
Couldn't find index page for 'cffi'
Download error on https://pypi.python.org/simple/
因此,pip尝试通过从官方PyPi存储库中查找并安装cffi
来解决嵌套的依赖项.它完全忽略了我已配置的存储库.
So pip tries to resolve the nested dependency by looking and installing cffi
from the official PyPi repository. It completely ignores the repo I have configured.
当我一个接一个地运行pip install cffi && pip install rpy2
时,一切都按预期运行.
When I run pip install cffi && pip install rpy2
one after another everything works as expected.
这是完整的错误输出:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8vuadu93/rpy2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-8vuadu93/rpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-8vuadu93/rpy2/pip-egg-info
cwd: /tmp/pip-install-8vuadu93/rpy2/
Complete output (25 lines):
Download error on https://pypi.python.org/simple/cffi/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'cffi' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for cffi>=1.13.1
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-8vuadu93/rpy2/setup.py", line 183, in <module>
'rinterface_lib/R_API_eventloop.h']}
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 128, in setup
_install_setup_requires(attrs)
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 123, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 513, in fetch_build_eggs
replace_conflicting=True,
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 774, in resolve
replace_conflicting=replace_conflicting
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1057, in best_match
return self.obtain(req, installer)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1069, in obtain
return installer(requirement)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 580, in fetch_build_egg
return cmd.easy_install(req)
File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 692, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('cffi>=1.13.1')
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
问题
这是Pip中的错误,还是rpy2的特定问题?还是我遗漏了一些东西?
运行以下命令会给我同样的错误:
Running the following commands gives me the same error:
pip install rpy2 --no-index --find-links http://private.com/artifactory/api/pypi/PyPI/simple
pip install rpy2 --index-url http://private.com/artifactory/api/pypi/PyPI/simple
我使用了-vvv
,看来问题出在setuptools
I used -vvv
and it seems like the problem occurs somewhere inside of setuptools
软件包rpy2
使用setuptools
,而该软件包再次使用easy_install.py
.它也可以与index_url
变量一起使用.但这不是pip.config
而是distutils.cfg
的值.
The package rpy2
uses setuptools
which again uses easy_install.py
. It also works with an index_url
variable. But it gets the value not from pip.config
but distutils.cfg
.
我确定了find / -name "distutils"
安装的所有Python版本.然后,我将具有以下内容的distutils.cfg
添加到这些目录中的每个目录:
I identified all Python versions I have installed with find / -name "distutils"
. Then I added the a distutils.cfg
with the following content to each of these directories:
[easy_install]
index_url = blablabla
现在工作了,我执行了pip install rpy2
,所有缺少的需求都一口气安装了
And now it works, I execute pip install rpy2
and all missing requirements are installed in one go
推荐答案
我相信这可能是由于 rpy2 的setup.py
中cffi
被列为setup_requires
的事实引起的. .最可能的原因是,必须cffi
来构建项目本身,然后才能安装.这种 build 依赖项不是直接由 pip 处理的,因此其index-url
选项无效.
I believe it could be caused by the fact that cffi
is listed as setup_requires
in rpy2's setup.py
. Most likely because cffi
is required to build the project itself before it can be installed. This kind of build dependencies are not handled by pip directly, so its index-url
option has no effect.
The solution is to tell setuptools about the alternative index in a distutils configuration file
[easy_install]
index_url = https://my.index-mirror.com
参考文献:
- "Controlling setup_requires" in pip's documentation
- setuptools, easy_install, and a custom pypi server
- distutils configuration file
这篇关于为什么Pip会忽略具有嵌套依赖项的已配置存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!