PIP: How to Cascade Requirements Files and Use Pri

2019-08-28 08:29发布

This question already has an answer here:

I am trying to deploy a Django app to Heroku where one of the required packages lives on https://testpypi.python.org/pypi and of course Django is on the main PyPI server.

My setup looks like this.

# requirements.txt
-r requirements/req2.txt
-r requirements/req3.txt
# requirements/req2.txt
Django==1.7.7
# requirements/req3.txt
-i https://testpypi.python.org/pypi
foo-bar==0.4

Running the command: pip install -r requirements.txt results in the following error.

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

So to me it looks like the -i argument in req3 is being set then pip tries to look for Django on the testpypi server.

I tried adding -i https://pypi.python.org/pypi to req2.txt but I still get the same error. (perhaps https://pypi.python.org/pypi is the wrong url)

In addition if I run either req*.txt file individually the installation of the package is successful?

How can one cascade requirements files and use private indexes?

Admittedly this question and this one are quite similar but neither deal with private indexs

1条回答
Melony?
2楼-- · 2019-08-28 08:42

It turns out that the correct method of dealing with private indexes is to use --extra-index-url switch. From the documentation of pip:

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

So, putting the line

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

on top of your requirements.txt should be enough. No need to cascade at all!

查看更多
登录 后发表回答