【问题标题】:pip requirements.txt with alternative index带有替代索引的 pip requirements.txt
【发布时间】:2011-01-29 10:41:45
【问题描述】:

我想将 repoze Zope2 安装的所有要求放在 pip requirements file 中。大多数 repoze 包似乎不在 PyPi 上,但有一个可供它们使用的替代 PyPi 索引here。但我不知道如何告诉 pip 将该索引与需求文件一起使用。对于单个包,很容易

pip install zopelib -i http://dist.repoze.org/zope2/2.10/simple/

我尝试了以下

pip install -r requirements.txt -i http://dist.repoze.org/zope2/2.10/simple/

或在我的 requirements.txt 中所有这些类型或排列:

zopelib -i http://dist.repoze.org/zope2/2.10/simple/
zopelib --index http://dist.repoze.org/zope2/2.10/simple/
-i http://dist.repoze.org/zope2/2.10/simple/ zopelib

或(因为documentation 表示“请注意,所有这些选项都必须单独一行。”)

--index http://dist.repoze.org/zope2/2.10/simple/
zopelib

那么,告诉 pip 使用http://dist.repoze.org/zope2/2.10/simple/ 作为索引的正确方法是什么?

【问题讨论】:

标签: python pip pypi


【解决方案1】:

在包/项目名称之前的需求文件中添加一个额外的索引位置:

--extra-index-url <Extra URLs other than index-url>
<some_project_name>

或者,您可以使用-i--index-url &lt;Base URL of the Python Package Index&gt;

参考:requirements file format

【讨论】:

  • 这对我有用。对于-ipip install 只能使用一个来源。
  • 使用--index-url而不是--extra-index-url来防止dependency confusion attacks
【解决方案2】:

requirements.txt:

-i http://dist.repoze.org/zope2/2.10/simple
zopelib

例子:

$ pip install -r requirements.txt
...
Successfully installed zopelib

【讨论】:

  • 对于那些好奇的人,-i--index-url 的缩写,如果有人喜欢明确的话。
  • 对于那些因安全警告而被拒绝连接的人,您可能需要将域添加为受信任的命令:-i http://some.domain.org/simple --trusted-host some.domain.org
  • 如果我有来自同一个 repo 的多个包,我是否必须为每个包包含索引 URL,或者它放置在文件中的位置是否重要?
  • @kadamb:我需要使用这种语法已经有一段时间了。我猜只包含一次选项就足够了,我不知道选项的顺序是否重要——您可以对其进行测试并将其发布为您自己的 StackOverflow 问题和答案(或者只是在此处发表评论,以帮助未来的访问者有类似问题)The docs might help
  • 有什么方法可以使用 setup.py 中的需求文件行来完成这项工作?
猜你喜欢
  • 2018-06-08
  • 1970-01-01
  • 2014-06-17
  • 2019-08-27
  • 2020-08-15
  • 2023-01-21
  • 2018-04-01
  • 2018-06-19
相关资源
最近更新 更多