gpt4 book ai didi

python - 配置 setup.py 以从存储库 URL 安装需求

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:51 25 4
gpt4 key购买 nike

我正在创建一个模块,需要准备我的 setup.py 文件以满足一些要求。其中一项要求是 PyPI 中已有的一个包的分支,因此我想直接引用我的 GitHub 存储库。

我尝试了两种配置,第一种是:

setup(
'name': 'mymodule',
# other arguments
install_requires=[
'myrequirement', # The dependency name
],
dependency_links=[
'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement', # This is my repository location
]
)

我使用 python setup.py sdist 创建我的模块的本地分发,当我运行 pip install path/to/module/dist/mymodule-0.1.tar.gz 它最终在 PyPI 而不是我的存储库上安装了版本。

另一个配置,我尝试更改需求名称以强制搜索依赖链接,如下所示:

setup(
'name': 'mymodule',
# other arguments
install_requires=[
'myrequirement_alt', # The dependency name with a suffix
],
dependency_links=[
'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt', # This is my repository location
]
)

但是有了这个,我最终只会得到一个错误,即 myrequirement_alt is not found...

所以我想问,在不使用 PyPI 的情况下实现这一目标的正确方法是什么?

最佳答案

要使依赖关系链接起作用,您需要将包的版本号添加到 https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt。 否则它将不知道要安装什么。

例如:

setup(
'name': 'mymodule',
# other arguments
install_requires=[
'myrequirement', # The dependency name
],
dependency_links=[
'https://github.com/ihhcarus/myrequirement.git#egg=myrequirement_alt-1.3' # Link with version at the end
]
)

请注意,我根本不建议使用依赖关系链接,因为它们已被弃用。相反,您应该使用需求文件。

关于python - 配置 setup.py 以从存储库 URL 安装需求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42769544/

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