Python Setup.py - 依赖项作为 TAR 或 GIT 的 url

mad*_*ote 2 python dependencies setuptools setup.py

根据我的研究,以下应该有效:

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,
    ...
)
Run Code Online (Sandbox Code Playgroud)

当建造轮子或鸡蛋时,一切都很好:python setup.py bdist_wheel

但是当尝试使用pip install -U dist/mypack-....whl.

我得到:

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)
Run Code Online (Sandbox Code Playgroud)

我尝试过同样的方法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
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)

但这不是干净的方式,因为轮子应该是独立的。

谢谢您的任何提示!


环境

  • 蟒蛇:3.7.0
  • 点:20.2.4
  • 安装工具:50.3.2

obl*_*lex 5

不久前,可以定义一个requirements.txt或类似的包,其中包含 PyPI 包的规范以及存储库和档案的链接。

\n

这需要解析requirements.txt并将它们分成“需求”和“依赖项”,其中“需求”将包含 PyPI 包和“依赖项”\xe2\x80\x94 链接的定义。

\n

对于这些, Setuptools 有不同的参数setup()install_requiresdependency_links

\n

它确实有效:人们能够定义 arequirements.txt并安装一个包 aspython setup.py install和 as pip install .。此外,可以通过pip install -r requirements.txt. 所有方法都有效,并且允许在一个地方定义所有需求,包括非 PyPI 链接。

\n

然而,自 v19 以来,对dependency_linksarg 的支持已被取消pip。这是奇怪的部分:它没有被 掉落setuptools。但还有更多。

\n

截至今日,pip

\n
    \n
  • 仅支持install_requires.
  • \n
  • install_requires对于包 ( ) 和独立或类似定义中的依赖关系,更喜欢使用 PEP 508 表示法requirements.txt
  • \n
  • 中止软件包的安装,这些软件包的install_requires.
  • \n
\n

您的依赖项定义混合了 2 种符号:前缀keras-contrib@来自 PEP 508,#egg=部分来自setuptools链接符号。

\n

这不是问题:pip将忽略“eggs”,因为名称之前已定义@

\n

我相信通过以下方式安装软件包pip效果很好,即:

\n
  pip install .\n
Run Code Online (Sandbox Code Playgroud)\n

但是,如果通过安装包就会出现问题setuptools,即:

\n
  python setup.py install\n
Run Code Online (Sandbox Code Playgroud)\n

setuptools不理解 PEP 508 符号并忽略install_requires. 截至今天,要建立setuptools以下链接,必须同时install_requires使用 和dependency_links,例如:

\n
setup(\n   ...\n   install_requires=[\n      ...\n      "keras_contrib==2.0.8",\n      ...\n   ],\n   dependency_links=[\n      "https://github.com/keras-team/keras-contrib/tarball/master#egg=keras_contrib-2.0.8",\n      ...\n   ],\n)\n
Run Code Online (Sandbox Code Playgroud)\n

这里有几个棘手的点:

\n
    \n
  • 单个依赖项在 2 个位置定义:包名称和用于解析包依赖项的install_requires链接。dependency_links
  • \n
  • 该链接不是git+https://.../....git,但它是一个存档链接:https://.../tarball/...
  • \n
  • 蛋名是在snake_case,不是在dash-case。虽然可以使用dash-case,但这不允许指定版本。
  • \n
  • 版本 ininstall_requires通过 分隔==,在dependency_links\xe2\x80\x94 中通过 分隔-
  • \n
  • 可以省略版本。但唯一可行的用例是 PyPI 中不存在该包并且很少更新。如果 PyPI 中存在该包,但需要未发布的版本,则必须指定版本。
  • \n
\n

糟糕的是:修复链接将会setuptools中断pip,因为 PEP 508 不允许指定版本。保留keras-contrib==x.y.z @ ...将使搜索包,其中不是版本,而是名称的一部分install_requires。同时,不指定版本将导致获取 PyPI 上可用的最新版本,而不是来自.pipkeras-contrib==x.y.z==x.y.zsetuptoolsdependency_links

\n

在您的情况下,PyPI 中既不存在keras-contrib也不en-core-web-sm存在,因此使用不指定版本的keras_contrib@git+https://...+可能会起作用。dependency_links

\n

否则,如果包依赖于链接,请坚持pip install .并避免使用。python setup.py install

\n

也可以看看:

\n\n
\n

琐事:GitHub 上的几个问题仍然悬而未决,PEP 508Active自 2015 年以来仍然处于状态。深入研究源代码会发现setuptools是 Python 的distutils的包装器。setuptools不是Python stdlib 的一部分,但distutils暗示stdlib 文档将在更新后删除setuptools。同时pip已经作为Python 的模块与Python 的安装捆绑在一起。然而我们还有pipfilespipenvpoetrycondapipxpip-toolsshivspack以及其余的。看起来有点势不可挡。

\n
\n