<p>简单的回答是:没有优先级,您可能应该避免完全使用<code> extra-index-url</code></p>
<hr/>
<p>这里有这样的问题和答案:<a href="https://github.com/pypa/pip/issues/5045#issuecomment-369521345" rel="nofollow noreferrer">https://github.com/pypa/pip/issues/5045#issuecomment-369521345</a></p>
<p><em>问题</em>:</p>
<blockquote>
<p>I have this in my pip.conf:</p>
<pre><code>[global]
index-url = https://myregistry-xyz.com
extra-index-url = https://pypi.python.org/pypi
</code></pre>
<p>Let's assume packageX exists in both registries and I run pip install packageX.</p>
<p>I expect pip to install packageX from <a href="https://myregistry-xyz.com" rel="nofollow noreferrer">https://myregistry-xyz.com</a>, but pip will use <a href="https://pypi.python.org/pypi" rel="nofollow noreferrer">https://pypi.python.org/pypi</a> instead.</p>
<p>If I switch the values for index-url and extra-index-url I get the same result. pypi is always prioritized.</p>
</blockquote>
<p><em>回答</em>:</p>
<blockquote>
<p>Packages are expected to be unique up to name and version, so two wheels with the same package name and version are treated as indistinguishable by pip. This is a deliberate feature of the package metadata, and not likely to change.</p>
</blockquote>
<hr/>
<p>我还建议阅读以下讨论:<a href="https://discuss.python.org/t/dependency-notation-including-the-index-url/5659" rel="nofollow noreferrer">https://discuss.python.org/t/dependency-notation-including-the-index-url/5659</a></p>
<p>本次讨论涉及的内容很多,其中一些内容显然超出了本问题的范围,但无论如何,所有内容都非常有用</p>
<p>在那里,应该有你的钥匙外卖:</p>
<p>理论上,Pip并没有将一个指数置于另一个指数之上。实际上,由于代码实现方式的巧合,可能总是先检查一个,但这不是您应该依赖的行为</p>
<blockquote>
<p>And what is a good way to be in control, that certain libraries will only be fetched from the private index if they exists there, and will not be looked for at PyPI?</p>
</blockquote>
<p>您应该设置和管理自己的包索引(devpi、pydist、jfrog artifactory、sonatype nexus等),并专门使用它,这意味着:<strong>永远不要使用<code> extra-index-url</code></strong>。这是您可以精确控制下载内容的唯一方法。除了几个依赖项之外,这个自定义存储库可能主要充当公共PyPI的代理</p>
<hr/>
<p>相关的</p>
<ul>
<li><a href="https://stackoverflow.com/q/58122738/11138259">pip: selecting index url based on package name?</a></li>
</ul>