如何使用 install_requires 从 setup.py 安装 git+https://

CIs*_*ies 6 python git pip setuptools setup.py

我有一个必须从 git+https 安装的项目:

我可以让它以这种方式工作:

virtualenv -p python3.5 bla
. bla/bin/activate
pip install numpy # must have numpy before the following pkg...
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
Run Code Online (Sandbox Code Playgroud)

但是,我想在 setup.py 文件中使用它install_requires

from setuptools import setup
setup(install_requires='git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI', setup_requires='numpy')
Run Code Online (Sandbox Code Playgroud)

然后,pip install -e .从包含setup.py

由于解析错误,这不起作用:

    Complete output (1 lines):                                                                                                             
    error in bla_bla setup command: 'install_requires' must be a string or list of strings containing valid project/version requireme
nt specifiers; Invalid requirement, parse error at "'+https:/'"                                                                             
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.  
Run Code Online (Sandbox Code Playgroud)

如果我安装 using pip install -r requires.txt(假设我在该文件中有相同的字符串)而不是使用 direct pip install git+......

如何修复这个解析错误?

到目前为止我尝试过的:

  1. 用 " / """ / ' / ''' 包裹字符串
  2. 在字符串前添加 'r'

phd*_*phd 11

install_requires 必须是一个字符串或一个带有名称和可选 URL 的字符串列表,以从以下位置获取包:

install_requires=[
    'pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
]
Run Code Online (Sandbox Code Playgroud)

请参阅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.