gpt4 book ai didi

github - PyPI install_requires 直接链接

转载 作者:行者123 更新时间:2023-12-05 04:48:29 25 4
gpt4 key购买 nike

我有一个 Python 库 ( https://github.com/jcrozum/PyStableMotifs ),我想在 PyPI 上发布。它依赖于另一个我无法控制的库 ( https://github.com/hklarner/PyBoolNet ),它只在 GitHub 上可用,特别是在 PyPI 上不可用。我的 setup.py 看起来像这样:

from setuptools import
setup(
... <other metadata> ...,
install_requires=[
'PyBoolNet @ git+https://github.com/hklarner/PyBoolNet@2.3.0',
... <other packages> ...
]
)

运行 pip install git+https://github.com/jcrozum/PyStableMotifs 完美运行,但由于 twine 出现以下错误,我无法将其上传到 PyPI:

requires_dist 的值无效。错误:不能有直接依赖:'PyBoolNet @git+https://github.com/hklarner/PyBoolNet@2.3.0'

我的理解是,出于安全原因,PyPI 禁止直接链接。尽管如此,PyBoolNet 是 PyStableMotifs 的硬性要求。我该怎么办?放弃 PyPI?

我只想让 pip install PyStableMotifs 为我的用户工作。理想情况下,此命令应安装依赖项,我不必维护两个版本的 setup.py。

否则,我考虑在 PyPI 上创建一个“虚拟”包,指导用户使用命令 pip install git+https://github.com/jcrozum/PyStableMotifs 进行安装。这是一个坏主意(甚至可能)吗?

是否已经针对这种情况建立了最佳实践或其他常见的解决方法?

编辑:现在,我有一个笨拙且完全不能令人满意的解决方法。我保留了两个版本;一个完美运行的 GitHub 版本,以及一个删除了 PyBoolNet 要求的 PyPI 版本。如果用户尝试在未安装 PyBoolNet 的情况下导入 PyStableMotifs,则会显示一条错误消息,其中包含 PyBoolNet 的安装说明。这在我看来远非理想,但在我找到更好的解决方案或 PyPI 修复此错误(或删除此功能,具体取决于您询问的对象)之前,我必须这样做。

最佳答案

我的建议是摆脱 install_requires 中的直接 URL,并告诉您的用户他们可以在哪里找到该依赖项 PyBoolNet,因为它不在 上PyPI。不要强制他们采用特定的安装方法,而是向他们展示示例。

也许只是简单地告诉您的用户:

This project depends on PyBoolNet, which is not available on PyPI. One place where you can find it is at: https://github.com/hklarner/PyBoolNet.

One way to install PyStableMotifs as well as its dependency PyBoolNet is to run the following command:

python -m pip install 'git+https://github.com/hklarner/PyBoolNet@2.3.0#egg=PyBoolNet' PyStableMotifs

您还可以准备一个 requirements.txt 文件并告诉您的用户:

Install with the following command:

python -m pip install --requirement https://raw.githubusercontent.com/jcrozum/PyStableMotifs/master/requirements.txt

requirements.txt 的内容可能是这样的:

git+https://github.com/hklarner/PyBoolNet@2.3.0#egg=PyBoolNet
PyStableMotifs

但最后,您真的应该让您的用户选择如何安装该依赖项。您的项目只需要声明它依赖于该库,而不是如何安装它。

关于github - PyPI install_requires 直接链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68073819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com