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

xjreopfe  于 2023-06-20  发布在  Git
关注(0)|答案(3)|浏览(184)

我有一个包,我正在推送到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

因此,我的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
)

但是运行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'"

在其他答案中已经建议,可以将类似于

git+https://github.com/themightyoarfish/svcca-gpu.git#egg=svcca

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:/'

问题:(如何)我可以将git仓库列为pip包的依赖项吗?

q5iwbnjs

q5iwbnjs1#

在为Pip指定git依赖项的50种左右的不同方法中,唯一一种达到我预期目的的方法是这一种(在PEP 508中概述):

svcca @ git+ssh://git@github.com/themightyoarfish/svcca-gpu

这可以在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/
gojuced7

gojuced72#

下一篇:关于How to state in requirements.txt a direct github source您可以使用以下语法从git remote repository添加package

-e git://github.com/themightyoarfish/svcca-gpu.git

参考:在可编辑模式下安装项目(即setuptools“develop mode”)从本地项目路径或带有-e的VCS URL

atmip9wb

atmip9wb3#

我们用pyproject.toml试过了,它也不适合我们。

requires = [
    "geci_plots @ git+https://github.com/IslasGECI/geci_plots.git@v0.4.0",
    "lmfit",
    "pandasql",
    "scikit-learn==1.1.3",
]

似乎直接引用不允许。

ERROR    HTTPError: 400 Bad Request from https://upload.pypi.org/legacy/        
         Invalid value for requires_dist. Error: Can't have direct dependency:  
         'geci_plots @ git+https://github.com/IslasGECI/geci_plots.git@v0.4.0'

我假设直接引用是GitHub仓库。

相关问题