[英]How can I use git repos as dependencies for my PyPi package?
我有一個要推送到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指定git依賴關系的50種左右不同方法中,唯一達到我預期目的的方法就是這種方法(PEP 508中的概述):
svcca @ git+ssh://git@github.com/themightyoarfish/svcca-gpu
可以在install_requires
中使用它,它解決了pip忽略dependency_links
的問題。
一個有趣的副作用是,不能以這種依賴關系將包上傳到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/
根據下一篇有關如何在requirements.txt中聲明狀態的文章,直接找到github源碼 。 您可以使用以下語法從git遠程存儲庫添加軟件包 :
-e git://github.com/themightyoarfish/svcca-gpu.git
參考:從本地項目路徑或帶有-e
的VCS URL以可編輯模式(即setuptools“開發模式”) 安裝項目
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.