【发布时间】:2019-07-20 02:27:23
【问题描述】:
我有一个要推送到 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 包的依赖项吗?
【问题讨论】:
-
链接的问题和最佳答案似乎没有解决问题,因为它处理需求文件,而不是
pip。这个想法必须以setup()理解的方式陈述需求。 -
我应该更清楚地说明
requirements.txt在这种情况下只是setuptools依赖项的代理。