Installing Packages from Multiple Servers from One

2019-01-15 15:20发布

I have tried the following two approaches without success.

The first with Cascading Requirements Files.

# 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

pip install -r requirements.txt results in pip not finding Django.

The second attempt was to include both requirements in a single file:

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

pip install -r requirements.txt results in the same error, pip not finding Django.

How can I use pip to install packages from different servers/index-urls?

标签: python pip
1条回答
趁早两清
2楼-- · 2019-01-15 15:29

The solution in either case is to add --extra-index-url <url> at the beginning of the requirements.txt file.

Example:

# requirements.txt
--extra-index-url https://testpypi.python.org/pypi
Django==1.7.7
django-stackexchange-feed==0.4

Or to use Cascading Requirements Files:

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

pip install -r requirements.txt will now work.

查看更多
登录 后发表回答