5

我正在尝试将 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

运行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))

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

所以我尝试了这个:

-i https://pypi.python.org/pypi/
Django==1.7.7
-i https://testpypi.python.org/pypi
foo-bar==0.4

它会导致相同的错误。

如果我在需求文件中只放置一个(不管是一个)包,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))
4

1 回答 1

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

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

于 2015-03-26T14:53:00.407 回答