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

问题描述 投票:1回答:1

我有一个必须从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'

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

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

然后,从包含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.  

如果我使用pip install -r requires.txt进行安装(假设我在该文件中具有相同的字符串),而使用直接pip install git+...时则不会发生此错误...

如何解决此解析错误?

到目前为止我尝试过的:

  1. 用“ /”“” /'/'''包裹字符串
  2. 在字符串前添加'r'
python git pip setuptools setup.py
1个回答
3
投票

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

install_requires=[
    'pycocotools @ git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
]

请参见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一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.