根据我的研究,以下应该起作用:
from setuptools import setup
from setuptools import find_packages
...
REQUIRES_INSTALL = [
'spacy==2.3.2',
'tensorflow==1.14.0',
'Keras==2.2.4',
'keras-contrib@git+https://github.com/keras-team/keras-contrib.git#egg=keras-contrib',
'en-core-web-sm@https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.0/en_core_web_sm-2.3.0.tar.gz#egg=en-core-web-sm'
]
...
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
install_requires=REQUIRES_INSTALL,
...
)
构建轮子或鸡蛋时,一切都很好:python setup.py bdist_wheel
.但是当尝试使用
pip install -U dist/mypack-....whl
安装软件包(whl 或 egg)时.我得到:
ERROR: Could not find a version that satisfies the requirement keras-contrib (from mypack==0.3.5) (from versions: none)
ERROR: No matching distribution found for keras-contrib (from mypack==0.3.5)
...
ERROR: Could not find a version that satisfies the requirement en-core-web-sm (from mypack==0.3.5) (from versions: none)
ERROR: No matching distribution found for en-core-web-sm (from mypack==0.3.5)
我曾尝试通过 setup.cfg
进行相同的操作但仍然没有运气。作为引用 - 所有这些依赖项在首先从
requirments.txt
安装它们时都有效然后安装轮子。spacy==2.3.2
tensorflow==1.14.0
Keras==2.2.4
keras-contrib@git+https://github.com/keras-team/keras-contrib.git#egg=keras-contrib
en-core-web-sm@https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.3.0/en_core_web_sm-2.3.0.tar.gz#egg=en-core-web-sm
pip install -r requirements.txt
pip install -U dist/mypack-....whl
但这不是干净的方式,因为轮子应该是独立的。谢谢你的任何提示!
环境
最佳答案
前一段时间可以定义单个 requirements.txt
或类似的,包含 PyPI 包的规范和存储库和文件的链接。
这需要解析 requirements.txt
并将它们拆分为“要求”和“依赖项”,其中“要求”将包含 PyPI 包和“依赖项”的定义——链接。
Setuptools 对 setup()
有不同的参数对于这些: install_requires
和 dependency_links
.
它确实有效:可以定义一个 requirements.txt
并安装一个包作为 python setup.py install
并作为 pip install .
.此外,可以通过 pip install -r requirements.txt
只安装依赖项。 .所有方法都有效并允许在一个地方定义所有要求,包括非 PyPI 链接。
但是,支持dependency_links
arg 被 pip
删除自 v19.这是奇怪的部分:它不会被 setuptools
丢弃.但还有更多。
截至今天,pip
:
install_requires
. install_requires
)和独立 requirements.txt
中的依赖项首选 PEP 508 表示法或类似。 install_requires
中包含链接. 您对依赖项的定义混合了 2 个符号:前缀如
keras-contrib@
来自 PEP 508 和 #egg=
零件来自 setuptools
链接符号。这不是问题:
pip
将忽略“eggs”,因为在 @
之前已经定义了名称.我相信通过
pip
安装软件包工作正常,即: pip install .
但是,如果通过 setuptools
安装软件包,则会出现问题。 , IE。: python setup.py install
setuptools
不理解 PEP 508 符号并忽略 install_requires
中的链接.截至今天,使setuptools
以下链接,都是 install_requires
和 dependency_links
必须使用,例如:setup(
...
install_requires=[
...
"keras_contrib==2.0.8",
...
],
dependency_links=[
"https://github.com/keras-team/keras-contrib/tarball/master#egg=keras_contrib-2.0.8",
...
],
)
这里有几个棘手的点:install_requires
中的包名和 dependency_links
中的链接解决包依赖问题。 git+https://.../....git
,但它是一个存档链接:https://.../tarball/...
. snake_case
,不在 dash-case
.虽然可以使用 dash-case
,这将不允许指定版本。 install_requires
中的版本通过 ==
分隔并在 dependency_links
— 通过 -
. 更糟糕的是:修复
setuptools
的链接会断pip
,因为 PEP 508 不允许指定版本。饲养 keras-contrib==x.y.z @ ...
在 install_requires
将使pip
搜索包裹 keras-contrib==x.y.z
,其中 ==x.y.z
不是版本,而是名称的一部分。同时,不指定版本会使setuptools
获取 PyPI 上可用的最新版本,而不是来自 dependency_links
的链接.在你的情况下
keras-contrib
也不是 en-core-web-sm
存在于 PyPI 中,因此使用 keras_contrib@git+https://...
+ dependency_links
没有指定版本可能会起作用。否则,坚持
pip install .
并避免使用 python setup.py install
如果包依赖于链接。也可以看看:
--process-dependency-links
until an alternative is implemented Trivia: several issues on GitHub are still open and PEP 508 is still in
Active
state since 2015. Digging around source code would reveal that setuptools is a wrapper around Python's distutils.setuptools
is not a part of Python's stdlib, but the docs ofdistutils
imply stdlib docs will be removed after docs ofsetuptools
will be updated. At the same timepip
is already bundled with Python's installations as Python's module. And yet we havepipfile
s,pipenv
,poetry
,conda
,pipx
,pip-tools
,shiv
,spack
, and the rest. Looks a bit overwhelming.
关于Python Setup.py - 作为对 TAR 或 GIT 的 url 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64482089/