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

发布于 2024-12-18 04:14:06 字数 132 浏览 3 评论 0 原文

在执行 PyPI 包的 python setup.py install 时是否有人遇到此警告?

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"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

聽兲甴掵 2024-12-25 04:14:06

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

吾性傲以野 2024-12-25 04:14:06

这是我谷歌搜索的第一个结果,但没有答案。
我发现升级 setuptools 解决了我的问题(并且 pip 是很好的措施)

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!

清晰传感 2024-12-25 04:14:06

我使用的是 python 2.7.11 的 Mac。我一直在尝试创建极其简单明了的项目,其中我唯一的要求是我可以运行 python setup.py install 并让 setup.py 使用 setup 命令,最好来自 distutils。除了我在这里注意到的之外,除了 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:UserWarning:未知的分发选项:“entry_points”
警告.warn(msg)

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

from distutils.core import setup
import setuptools  # noqa

警告就会消失。

请注意,我没有使用 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 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.

¢好甜 2024-12-25 04:14:06

注意注意!前面的答案不完美。要获取有关 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.

夏末染殇 2024-12-25 04:14:06

结论

distutils 不支持 install_requiresentry_pointssetuptools 支持。

setup.py 中的 from distutils.core import setup 更改为 from setuptools import setup 或重构您的 setup.py仅使用 distutils 功能。

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

如果您像我一样想要将 setuptools 转换为 distutils

  1. setup.py 中删除 install_requires 并使用requirements.txtpip
  2. entry_points 更改为 scripts (doc) 并重构依赖于 entry_points 是带有 shebangs 和入口点的完整脚本。

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.
嘿嘿嘿 2024-12-25 04:14:06

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

幸福丶如此 2024-12-25 04:14:06
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

等待我真够勒 2024-12-25 04:14:06

据我所知,这是 setuptools 中的一个错误,在调用标准库中的基类之前,它不会删除 setuptools 特定选项: https://bitbucket.org/pypa/setuptools/issue/29/avoid-userwarnings-emissed-when-calling

如果您有无条件 import setuptools您的 setup.py (如果使用 setuptools 特定选项,您应该这样做),那么脚本没有因 ImportError 失败的事实表明 setuptools 正确安装。

您可以按如下方式消除警告:

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

如果您使用无条件导入,则在未安装 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 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)

南城追梦 2024-12-25 04:14:06

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

注定孤独终老 2024-12-25 04:14:06

如果您遵循官方文档,它就可以正常工作:

import setuptools
setuptools.setup(...)

来源:https:/ /packaging.python.org/tutorials/packaging-projects/#creating-setup-py

It works fine if you follow the official documentation:

import setuptools
setuptools.setup(...)

Source: https://packaging.python.org/tutorials/packaging-projects/#creating-setup-py

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文