编程语言
首页 > 编程语言> > python-格式化pip的requirements.txt文件,其中一个或多个程序包具有不同的index-url

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

作者:互联网

这个问题已经在这里有了答案:            >            Installing Packages from Multiple Servers from One or More Requirements File                                    1个
我正在尝试将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试图在testpypi上找到Django

所以我尝试了这个:

-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是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))

解决方法:

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

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

All dependencies specified in that requirements file will resolve against that index.

解决方法是,您可以创建多个需求文件并对其进行级联:

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

If you would like to utilize multiple requirements files in your codebase, you can include the contents of another requirements file with pip:

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

更新:事实证明,处理私有索引的正确方法是使用–extra-index-url开关.从documentation of pip

Note that using –index-url removes the use of PyPI, while using –extra-index-url will add additional indexes.

所以,把线

--extra-index-url https://testpypi.python.org/pypi

在您的requirements.txt之上就足够了.根本不需要级联!

标签:heroku,requirements-txt,python,pip
来源: https://codeday.me/bug/20191120/2044916.html