如何使用git repos作为PyPi包的依赖项?

oar*_*ish 5 python git pip pypi

我有一个要推送到PyPi的程序包,某些功能不是程序包,而是可安装的git存储库。我requirements.txt看起来像这样

sphinx_bootstrap_theme>=0.6.5
matplotlib>=2.2.0
numpy>=1.15.0
sphinx>=1.7.5
sphinx-argparse>=0.2.2
tensorboardX
tqdm>=4.24.0
Cython>=0.28.5

# git repos
git+git://github.com/themightyoarfish/svcca-gpu.git
Run Code Online (Sandbox Code Playgroud)

因此,我setup.py具有以下内容:

#!/usr/bin/env python

from distutils.core import setup
import setuptools
import os

with open('requirements.txt', mode='r') as f:
    requirements = f.read()
    required_pkgs, required_repos = requirements.split('# git repos')
    required_pkgs = required_pkgs.split()
    required_repos = required_repos.split()

with open('README.md') as f:
    readme = f.read()

setup(name=...
      ...
      packages=setuptools.find_packages('.', include=[...]),
      install_requires=required_pkgs,
      dependency_links=required_repos,
      zip_safe=False,   # don't install egg, but source
)
Run Code Online (Sandbox Code Playgroud)

但是运行pip install <package>实际上并不会安装git依赖项。我认为pip实际上并没有使用安装脚本。当我python setup.py install手动运行时,它可以工作。

编辑

我也尝试过删除存储库dependency_links并仅使用install_requires它,但是从GitHub(包括上述文件的项目)安装存储库时,遇到了

    Complete output from command python setup.py egg_info:
error in ikkuna setup command: 'install_requires' must be a string or 
list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'+git://g'"
Run Code Online (Sandbox Code Playgroud)

在其他答案中有人建议可以放一些东西

git+https://github.com/themightyoarfish/svcca-gpu.git#egg=svcca
Run Code Online (Sandbox Code Playgroud)

进入requirements.txt,但失败了

   error in <pkg> setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'+https:/'
Run Code Online (Sandbox Code Playgroud)

问题:(如何)我可以列出git存储库作为pip包的依赖项吗?

oar*_*ish 10

在为 Pip 指定 git 依赖项的 50 种左右不同的方法中,唯一一种符合我的意图的是这个(PEP 508 中的概述):

svcca @ git+ssh://git@github.com/themightyoarfish/svcca-gpu
Run Code Online (Sandbox Code Playgroud)

这个可以在 中使用install_requires,解决了dependency_links被pip忽略的问题。

一个有趣的副作用是无法将包上传到具有此类依赖项的 PyPi:

HTTPError: 400 Client Error: Invalid value for requires_dist. Error: Can't have direct dependency: 'svcca @ git+ssh://git@github.com/themightyoarfish/svcca-gpu' for url: https://upload.pypi.org/legacy/
Run Code Online (Sandbox Code Playgroud)

  • 在他们改变这一点之前,“不要使用 PyPi”是唯一的解决方案。 (3认同)
  • 我*必须*向 PyPi 发布一个包。所以我最终发布了两个包:首先是直接依赖项,然后在将直接依赖项转换为常规依赖项后发布我的实际包! (3认同)

R. *_*cía 0

根据下一篇与如何在requirements.txt中声明直接github源相关的文章。\n您可以使用以下语法从git远程存储库添加包:

\n\n
-e git://github.com/themightyoarfish/svcca-gpu.git\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考:\n从本地项目路径或 VCS URL 以可编辑模式安装项目(即 setuptools \xe2\x80\x9cdevelop mode\xe2\x80\x9d)-e

\n