什么决定了“pip”将使用哪个索引?

2024-06-25 23:36:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望pip从我的舵手室安装wheel,并且仅当轮子从舵手室丢失时回退到PyPI(通过缓存代理)。在

我想通过打电话来达到这个目的

pip install -U --index-url $PYPI_PROXY_URL --find-links $WHEELHOUSE_URL \
            -r requirements.txt

然而,尽管wheelhouse拥有所有所需的包,但它并没有确定从哪里获得包,而是在它们的来源,代理PyPI或wheelhouse。在

我希望这是确定性的,总是先选择驾驶室。使用pip如何实现这一点?在

我知道--no-index会迫使它只使用舵手室,但我想保留对舵手室丢失的包进行回退的能力。在


Tags: installpip目的pypiurl代理indexfind
1条回答
网友
1楼 · 发布于 2024-06-25 23:36:49

深入研究pip的源代码,我发现:

  1. 使用内部^{}函数对有效候选项进行排序,其工作原理如下:

        If not finding wheels, then sorted by version only.
        If finding wheels, then the sort order is by version, then:
          1. existing installs
          2. wheels ordered via Wheel.support_index_min(self.valid_tags)
          3. source archives
        Note: it was considered to embed this logic into the Link
              comparison operators, but then different sdist links
              with the same version, would have to be considered equal
    
  2. 其他条件相同时,它回到hardcoded顺序,即:

    1. 本地文件系统
    2. 索引URL
    3. 查找链接URL
    4. 依赖链接URL

从pip9.0.1开始,上面的顺序是硬编码的,所以没有办法使用设置或参数来更改它。在

相关问题 更多 >