为 pip 格式化一个 requirements.txt 文件,其中一个或多个包具有不同的 index-url

rob*_*bmj 5 python pip heroku requirements.txt

我正在尝试将 Django 应用程序部署到 Heroku,其中一个必需的包存在于https://testpypi.python.org/pypi其中,当然 Django 位于主 PyPI 服务器上。

requirements.txt文件如下所示:

Django==1.7.7
-i https://testpypi.python.org/pypi
foo-bar==0.4
Run Code Online (Sandbox Code Playgroud)

运行pip install -r requirements.txt失败并出现以下错误:

Could not find any downloads that satisfy the requirement Django==1.7.7 (from -r requirements.txt (line 1))
Cleaning up...
No distributions at all found for Django==1.7.7 (from -r requirements.txt (line 1))
Run Code Online (Sandbox Code Playgroud)

所以看起来pip是在试图找到 Djangotestpypi

所以我试过这个:

-i https://pypi.python.org/pypi/
Django==1.7.7
-i https://testpypi.python.org/pypi
foo-bar==0.4
Run Code Online (Sandbox Code Playgroud)

它导致相同的错误。

如果我在需求文件中只放置一个(无关紧要)包,pip 能够找到该包并安装它。

问题:index-url在单个文件中指定可由命令读取的多个不同参数的正确语法是什么pip install -r file

我认为这并不重要,但 python 是 3.4.0 版,而 pip 是 version pip 1.5.2

我已将 pip 更新到 6.0.8 版,错误现在显示为:

Could not find any downloads that satisfy the requirement Django==1.7.7 (from -r requirements.txt (line 2))
No distributions at all found for Django==1.7.7 (from -r requirements.txt (line 2))
Run Code Online (Sandbox Code Playgroud)

Sel*_*cuk 11

根据定义,任何私有索引定义都将应用于每个包

https://devcenter.heroku.com/articles/python-pip#private-indexes

该需求文件中指定的所有依赖项都将针对该索引进行解析。

作为一种解决方法,您可以创建多个需求文件并将它们级联:

https://devcenter.heroku.com/articles/python-pip#cascading-requirements-files

如果你想在你的代码库中使用多个需求文件,你可以使用 pip 包含另一个需求文件的内容:

-r ./path/to/prod-requirements.txt

更新:事实证明,处理私有索引的正确方法是使用--extra-index-urlswitch。从pip文档中

请注意,使用 --index-url 会删除 PyPI 的使用,而使用 --extra-index-url 会添加额外的索引。

所以,把线

--extra-index-url https://testpypi.python.org/pypi
Run Code Online (Sandbox Code Playgroud)

在你之上requirements.txt应该就足够了。根本不需要级联!