pypi UserWarning:未知的分发选项:“install_requires”
在执行 PyPI 包的 python setup.py install 时是否有人遇到此警告?
install_requires
定义包需要什么。许多 PyPI 包都有此选项。怎么会是“未知的分发选项”呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
python setup.py
使用不支持 install_requires 的 distutils。 setuptools 可以,也可以分发(它的后继者),pip(使用其中一个)也可以。但你实际上必须使用它们。即通过easy_install
命令或pip install
调用 setuptools。另一种方法是从 setup.py 中的 setuptools 导入安装程序,但这不是标准的,并且使得每个想要使用您的包的人都必须安装 setuptools。
python setup.py
uses distutils which doesn't support install_requires. setuptools does, also distribute (its successor), and pip (which uses either) do. But you actually have to use them. I.e. call setuptools through theeasy_install
command orpip install
.Another way is to import setup from setuptools in your setup.py, but this not standard and makes everybody wanting to use your package have to have setuptools installed.
这是我谷歌搜索的第一个结果,但没有答案。
我发现升级 setuptools 解决了我的问题(并且 pip 是很好的措施)
希望这可以帮助下一个人找到此链接!
This was the first result on my google search, but had no answer.
I found that upgrading setuptools resolved the issue for me (and pip for good measure)
Hope this helps the next person to find this link!
我使用的是 python 2.7.11 的 Mac。我一直在尝试创建极其简单明了的项目,其中我唯一的要求是我可以运行 python setup.py install 并让 setup.py 使用 setup 命令,最好来自 distutils。除了我在这里注意到的之外,除了
setup()
的 kwargs 之外,实际上没有其他导入或代码。当我的
setup.py
文件的导入为:当我使用此文件时,我收到警告,例如
如果我将导入(以及没有其他)更改为以下内容:
警告就会消失。
请注意,我没有使用 setuptools,只是导入它会更改行为,使其不再发出警告。对我来说,这是真正令人困惑的差异的原因,我使用的一些项目给出了这些警告,而其他一些项目则没有。
显然,某种形式的猴子修补正在发生,并且它受到是否完成导入的影响。这可能不是每个研究这个问题的人的情况,但对于我工作的狭窄环境来说,这就是我正在寻找的答案。
这与其他(社区)评论一致,该评论说 distutils 应该 Monkeypatch setuptools,并且他们在安装 Ansible 时遇到了问题。 Ansible 过去似乎曾尝试允许在没有 setuptools 的情况下进行安装,但后来又放弃了这一做法。
https://github.com/ansible/ansible/blob/devel/setup.py
很多事情都悬而未决……但是如果您正在为一个简单的项目寻找一个简单的答案,您可能应该只导入 setuptools。
I'm on a Mac with python 2.7.11. I have been toying with creating extremely simple and straightforward projects, where my only requirement is that I can run
python setup.py install
, and havesetup.py
use the setup command, ideally from distutils. There are literally no other imports or code aside from the kwargs tosetup()
other than what I note here.I get the error when the imports for my
setup.py
file are:When I use this, I get warnings such as
If I change the imports (and nothing else) to the following:
The warnings go away.
Note that I am not using
setuptools
, just importing it changes the behavior such that it no longer emits the warnings. For me, this is the cause of a truly baffling difference where some projects I'm using give those warnings, and some others do not.Clearly, some form of monkey-patching is going on, and it is affected by whether or not that import is done. This probably isn't the situation for everyone researching this problem, but for the narrow environment in which I'm working, this is the answer I was looking for.
This is consistent with the other (community) comment, which says that distutils should monkeypatch setuptools, and that they had the problem when installing Ansible. Ansible appears to have tried to allow installs without having setuptools in the past, and then went back on that.
https://github.com/ansible/ansible/blob/devel/setup.py
A lot of stuff is up in the air... but if you're looking for a simple answer for a simple project, you should probably just import setuptools.
注意! 注意!前面的答案不完美。要获取有关 Python 世界中打包状态的“最新备忘录”,请阅读 这篇相当详细的文章。
我在尝试构建/安装 ansible 时刚刚遇到了这个问题。问题似乎是 distutils 确实 不支持 install_requires 。 setuptools 应该 动态地给 distutils 打上猴子补丁,但事实并非如此,可能是因为 setuptools 的最后一个版本是2009 年的 0.6c11,而 distutils 是一个核心 Python 项目。
因此,即使在手动安装 setuptools-0.6c11-py2.7.egg 后,运行 setup.py 也只会获取 distutils dist.py,而不是来自 site-packages/setuptools/ 的 distutils dist.py。
setuptools 文档还提示使用 ez_setup 而不是 distutils 。
然而,setuptools 本身现在是由 distribute 提供的,并且 setup() 的风格支持 install_requires。
ATTENTION! ATTENTION! Imperfect answer ahead. To get the "latest memo" on the state of packaging in the Python universe, read this fairly detailed essay.
I have just ran into this problem when trying to build/install ansible. The problem seems to be that distutils really doesn't support install_requires. Setuptools should monkey-patch distutils on-the-fly, but it doesn't, probably because the last release of setuptools is 0.6c11 from 2009, whereas distutils is a core Python project.
So even after manually installing the setuptools-0.6c11-py2.7.egg running setup.py only picks up distutils dist.py, and not the one from site-packages/setuptools/.
Also the setuptools documentation hints to using ez_setup and not distutils.
However, setuptools is itself provided by distribute nowadays, and that flavor of setup() supports install_requires.
结论:
distutils
不支持install_requires
或entry_points
,setuptools
支持。将 setup.py 中的
from distutils.core import setup
更改为from setuptools import setup
或重构您的 setup.py仅使用distutils
功能。我来到这里是因为我没有意识到
entry_points
只是一个setuptools
功能。如果您像我一样想要将
setuptools
转换为distutils
:install_requires
并使用requirements.txt 与pip
entry_points
更改为scripts
(doc) 并重构依赖于entry_points
是带有 shebangs 和入口点的完整脚本。In conclusion:
distutils
doesn't supportinstall_requires
orentry_points
,setuptools
does.change
from distutils.core import setup
in setup.py tofrom setuptools import setup
or refactor your setup.py to use onlydistutils
features.I came here because I hadn't realized
entry_points
was only asetuptools
feature.If you are here wanting to convert
setuptools
todistutils
like me:install_requires
from setup.py and just use requirements.txt withpip
entry_points
toscripts
(doc) and refactor any modules relying onentry_points
to be full scripts with shebangs and an entry point.这是来自 distutils 的警告,表明您没有安装 setuptools。
从 http://pypi.python.org/pypi/setuptools 安装它将会删除警告。
This is a warning from distutils, and is a sign that you do not have setuptools installed.
Installing it from http://pypi.python.org/pypi/setuptools will remove the warning.
它将安装任何缺少的标头。它解决了我的问题
It will install any missing headers. It solved my issue
据我所知,这是 setuptools 中的一个错误,在调用标准库中的基类之前,它不会删除 setuptools 特定选项: https://bitbucket.org/pypa/setuptools/issue/29/avoid-userwarnings-emissed-when-calling
如果您有无条件
import setuptools
您的setup.py
(如果使用 setuptools 特定选项,您应该这样做),那么脚本没有因ImportError
失败的事实表明 setuptools 正确安装。您可以按如下方式消除警告:
仅如果您使用无条件导入,则在未安装 setuptools 的情况下将完全失败:)
(我在帖子的结帐中看到了相同的行为-merger setuptools repo,这就是为什么我确信这是一个 setuptools 错误而不是系统配置问题,我预计预合并分发也会遇到同样的问题)
As far as I can tell, this is a bug in setuptools where it isn't removing the setuptools specific options before calling up to the base class in the standard library: https://bitbucket.org/pypa/setuptools/issue/29/avoid-userwarnings-emitted-when-calling
If you have an unconditional
import setuptools
in yoursetup.py
(as you should if using the setuptools specific options), then the fact the script isn't failing withImportError
indicates that setuptools is properly installed.You can silence the warning as follows:
Only do this if you use the unconditional import that will fail completely if setuptools isn't installed :)
(I'm seeing this same behaviour in a checkout from the post-merger setuptools repo, which is why I'm confident it's a setuptools bug rather than a system config problem. I expect pre-merge distribute would have the same problem)
我现在在使用 Python2.7 的遗留工具中看到了这一点,其中构建(如 Dockerfile)会安装未固定的依赖项,例如 pytest。 PyTest 已放弃对 Python 2.7 的支持,因此您可能需要指定版本 <新包发布。
或者如果可行的话,硬着头皮将该应用程序转换为 Python 3。
I've now seen this in legacy tools using Python2.7, where a build (like a Dockerfile) installs an unpinned dependancy, for example pytest. PyTest has dropped Python 2.7 support, so you may need to specify version < the new package release.
Or bite the bullet and convert that app to Python 3 if that is viable.
如果您遵循官方文档,它就可以正常工作:
来源:https:/ /packaging.python.org/tutorials/packaging-projects/#creating-setup-py
It works fine if you follow the official documentation:
Source: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py