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

标签 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,
    ...
)
构建轮子或鸡蛋时,一切都很好: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
但这不是干净的方式,因为轮子应该是独立的。
谢谢你的任何提示!

环境
  • Python:3.7.0
  • 点:20.2.4
  • 设置工具:50.3.2
  • 最佳答案

    前一段时间可以定义单个 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_requiresdependency_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",
          ...
       ],
    )
    
    这里有几个棘手的点:
  • 单个依赖项在 2 个地方定义: install_requires 中的包名和 dependency_links 中的链接解决包依赖问题。
  • 链接不是git+https://.../....git ,但它是一个存档链接:https://.../tarball/... .
  • 鸡蛋名称在 snake_case ,不在 dash-case .虽然可以使用 dash-case ,这将不允许指定版本。
  • install_requires 中的版本通过 == 分隔并在 dependency_links — 通过 - .
  • 可以省略版本。但唯一可行的用例是如果包不存在于 PyPI 中并且很少更新。如果包存在于 PyPI 中,但需要未发布的版本,则必须指定版本。

  • 更糟糕的是:修复 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如果包依赖于链接。
    也可以看看:
  • PEP 508
  • PEP508: why either version requirement or URL but not both?
  • How can I make setuptools install a package that's not on PyPI?
  • pip install dependency links
  • pip3 setup.py install_requires PEP 508 git URL for private repo
  • Why is dependency links in setup.py deprecated?
  • Changing PEP 508 URLs in setup.py doesn't reinstall the dependency
  • Updating remote links with new URLs for PEP508 functionality
  • Requirements using PEP 508 direct references ignore the URL
  • Suggest alternatives for --process-dependency-links
  • Un-deprecate --process-dependency-links until an alternative is implemented
  • Changes to the pip dependency resolver in 20.3 (2020)

  • 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 of distutils imply stdlib docs will be removed after docs of setuptools will be updated. At the same time pip is already bundled with Python's installations as Python's module. And yet we have pipfiles, 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/

    相关文章:

    asp.net - 如何处理 ASP.net 的神秘隐藏值? (__VIEWSTATE)

    java - 将测试数据从一个测试用例传递到另一个测试用例

    jboss - 我如何添加一个 jboss 7.1 模块,其中包含从服务器的主 ear 文件中的类实现/扩展的类?

    python - 如何在 python setup.py 中运行测试套件

    Python + Twisted + FtpClient + SOCKS

    python - 带有 pygobject 的 pango 属性

    python - 如何使用pyramid.wsgi中ini文件的相对路径作为pyramid.paster.get_app的参数?

    c++ - 项目依赖顺序 - VS2013

    setuptools - 相当于诗歌中的 `python setup.py develop`

    python setuptools在centos中的安装