问题:pypi UserWarning:未知分发选项:“ install_requires”

执行python setup.py installPyPI包时,有人会遇到此警告吗?

install_requires定义软件包的要求。许多PyPI软件包都有此选项。怎么可能是“未知分发选项”?

Does anybody encounter this warning when executing python setup.py install of a PyPI package?

install_requires defines what the package requires. A lot of PyPI packages have this option. How can it be an “unknown distribution option”?


回答 0

python setup.py使用不支持install_requires的distutils。setuptools这样做,还分发(它的后继),而pip(使用这两者之一)这样做。但是实际上您必须使用它们。即通过easy_install命令或调用setuptools pip install

另一种方法是从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 the easy_install command or pip 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.


回答 1

这是我的Google搜索的第一个结果,但没有答案。我发现升级setuptools可以为我解决问题(并且可以通过点子获得很好的效果)

pip install --upgrade pip
pip install --upgrade setuptools

希望这有助于下一个人找到此链接!

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)

pip install --upgrade pip
pip install --upgrade setuptools

Hope this helps the next person to find this link!


回答 2

注意注意!前面的答案不完善。要获取有关Python宇宙中包装状态的“最新备忘”,请阅读此相当详细的文章

我刚尝试构建/安装ansible时遇到了这个问题。问题似乎是distutils确实不支持 install_requires。Setuptools 应该动态地对distutils进行Monkey补丁,但事实并非如此,这可能是因为setuptools的最新版本是2009年的0.6c11,而distutils是Python的核心项目。

因此,即使在手动安装setuptools-0.6c11-py2.7.egg之后运行setup.py,也只能选择distutils dist.py,而不会从site-packages / setuptools /中获取。

setuptools文档还提示您使用ez_setup而不是distutils。

但是,setuptools本身现在由分发服务器提供,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.


回答 3

我在使用python 2.7.11的Mac上。我一直在创建极其简单明了的项目,我唯一的要求就是我可以运行python setup.py install,并且setup.py使用了distutils的setup命令。除了setup()我在这里提到的内容以外,除了kwargs之外,实际上没有其他导入或代码。

当我的setup.py文件导入为时,出现错误:

from distutils.core import setup

使用此功能时,我会收到诸如

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267:用户警告:未知的分发选项:’entry_points’warnings.warn(味精)

如果我将导入(以及其他内容)更改为以下内容:

from distutils.core import setup
import setuptools  # noqa

警告消失。

请注意,我没有使用setuptools,只是导入它会更改行为,以使其不再发出警告。对我来说,这是造成真正莫名其妙的差异的原因,其中我正在使用的某些项目发出这些警告,而另一些则没有。

显然,某种形式的Monkey修补正在进行中,并且受导入是否完成的影响。这可能不是每个研究此问题的人的情况,但是对于我正在工作的狭窄环境,这就是我一直在寻找的答案。


这与其他(社区)评论一致,该评论说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 have setup.py use the setup command, ideally from distutils. There are literally no other imports or code aside from the kwargs to setup() other than what I note here.

I get the error when the imports for my setup.py file are:

from distutils.core import setup

When I use this, I get warnings such as

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘entry_points’ warnings.warn(msg)

If I change the imports (and nothing else) to the following:

from distutils.core import setup
import setuptools  # noqa

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.


回答 4

这是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.


回答 5

sudo apt-get install python-dev  # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

它将安装所有缺少的标题。它解决了我的问题

sudo apt-get install python-dev  # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

It will install any missing headers. It solved my issue


回答 6

结论

distutils不支持install_requiresentry_pointssetuptools不。

变化from distutils.core import setupsetup.pyfrom setuptools import setup或重构你的setup.py只使用distutils功能。

我来这里是因为我没有意识到entry_points只是一个setuptools功能。

如果你在这里想转换setuptoolsdistutils像我这样的:

  1. install_requiressetup.py中删除,然后仅将requirements.txtpip
  2. 更改entry_pointsscriptsdoc)并重构所有依赖于entry_points带有shebang和入口点的完整脚本的模块。

In conclusion:

distutils doesn’t support install_requires or entry_points, setuptools does.

change from distutils.core import setup in setup.py to from setuptools import setup or refactor your setup.py to use only distutils features.

I came here because I hadn’t realized entry_points was only a setuptools feature.

If you are here wanting to convert setuptools to distutils like me:

  1. remove install_requires from setup.py and just use requirements.txt with pip
  2. change entry_points to scripts (doc) and refactor any modules relying on entry_points to be full scripts with shebangs and an entry point.

回答 7

据我所知,这是setuptools中的一个错误,在调用标准库中的基类之前,它没有删除setuptools的特定选项:https ://bitbucket.org/pypa/setuptools/issue/29 /避免在调用时发出用户警告

如果你有一个无条件的import setuptools在你setup.py(你应该如果使用setuptools的特定选项),那么实际上脚本没有与失败ImportError表明,setuptools的安装是否正确。

您可以按以下方式使警告静音:

python -W ignore::UserWarning:distutils.dist setup.py <any-other-args>

只要当您使用无条件导入执行此操作,如果未安装setuptools,导入将完全失败:)

(我在合并后setuptools存储库的签出中看到了相同的行为,这就是为什么我确信这是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 your setup.py (as you should if using the setuptools specific options), then the fact the script isn’t failing with ImportError indicates that setuptools is properly installed.

You can silence the warning as follows:

python -W ignore::UserWarning:distutils.dist setup.py <any-other-args>

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)


回答 8

我现在已经在使用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.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。