【问题标题】:How to install git+https:// from setup.py using install_requires如何使用 install_requires 从 setup.py 安装 git+https://
【发布时间】:2020-06-10 09:00:48
【问题描述】:

我有一个项目,我必须从 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】:

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

【讨论】:

  • 我将为python setup.py installpip install . 部分添加此参考:comment from pganssle in the discussion "Setuptools install fails with PEP508 URLs" in setuptools's issue tracker: "我们迄今为止的政策是,如果使用pip install 可以解决您的问题,你应该使用pip install,我们不会解决这个问题"
  • 这很糟糕,因为pip install "pkg_name" / pip install -r <requirements_file>pip install -e . 之间存在不一致。还是谢谢!
  • @ClsForCookies 不一致的地方是什么?我相信如果所有要求都遵循 PEP 508 并且不直接调用setup.py 那么它应该是一致的。
  • 你能说出这部分在命令中的作用吗? #subdirectory=PythonAPI
  • @PrinceMathur 听说过一个叫做“documentation”的东西吗? “search”呢?
猜你喜欢
  • 2021-10-26
  • 2022-01-14
  • 2020-12-13
  • 2018-04-05
  • 2016-05-06
  • 2019-12-10
  • 2021-09-02
  • 1970-01-01
  • 2012-07-28
相关资源
最近更新 更多