【问题标题】:Installing dependency from a VCS repo subdirectory using setuptools使用 setuptools 从 VCS 存储库子目录安装依赖项
【发布时间】:2020-05-21 08:45:20
【问题描述】:

我正在尝试使用 setuptools 从 VCS 和子目录中安装依赖项。

我的setup.py 看起来像这样:

#!/usr/bin/env python3

from setuptools import setup

required = [
    "package"
]
dependency_links = [
    "git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version"
]

setup(install_requires=required, dependency_links=dependency_links)

在 virtualenv 中运行 python3 setup.py install,我收到以下错误:

Download error on git+ssh://git@host/repo.git@tag#subdirectory=subdir#egg=package-version: unknown url type: git+ssh -- Some packages may not be found!

为了调试,我使用了以下公共 Github 存储库:

required = [
    "pycocotools"
]
dependency_links = [
    "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0"
]

建议使用此示例here 作为类似问题的解决方案。 我得到了同样的unknown url type 错误(包最终是通过 PyPI 检索的,而不是通过 VCS URL !)。

我尝试过的

git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI#egg=pycocotools-2.0
  • python3 setup.py install: unknown url type: git+https -- Some packages may not be found!
  • pip3 install: ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0': '/tmp/pip-install-lwpbj7yv/pycocotools-2.0/PythonAPI#egg=pycocotools-2.0'
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools-2.0
  • python3 setup.py install: unknown url type: git+https -- Some packages may not be found!
  • pip3 install:好的,但是WARNING: Generating metadata for package pycocotools-2.0 produced metadata for project name pycocotools. Fix your #egg=pycocotools-2.0 fragments.
git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools
  • python3 setup.py install: unknown url type: git+https -- Some packages may not be found!
  • pip3 install:好的

我也尝试删除所有这些 URL 的 git+,但它是 cannot detect archive format

我正在使用的版本

  • 设置工具 46.4.0
  • python 3.6.9
  • 点 20.1.1

【问题讨论】:

    标签: python-3.x setuptools


    【解决方案1】:

    dependency_links 被宣布为过时,最后在pip 19.0 中宣布removed。它的替代品是 install_requires,具有特殊语法(自 pip 19.1 起支持):

    install_requires=[
        'package_name @ git+https://gitlab.com/<PRIVATE_ORG>/<PRIVATE_REPO>.git@<COMMIT_ID>'
    ]
    

    https://pip.readthedocs.io/en/stable/reference/pip_install/#requirement-specifiershttps://www.python.org/dev/peps/pep-0440/#direct-references

    这需要pip install,包括pip install .,不适用于python setup.py install

    在你的情况下:

    install_requires=[
        "package @ git+ssh://git@host/repo.git@tag#subdirectory=subdir"
    ]
    
    setup(install_requires=install_requires)
    

    例如:

    install_requires=[
        pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI
    ]
    

    【讨论】:

    • 谢谢!早些时候我偶然发现了这种package @ url 语法,但我没有尝试使用pip install .
    猜你喜欢
    • 2014-06-28
    • 2016-05-27
    • 2014-10-02
    • 1970-01-01
    • 2012-02-01
    • 2015-10-27
    • 2019-06-21
    • 2016-11-02
    • 2021-12-27
    相关资源
    最近更新 更多