【问题标题】:What determines which index `pip` is going to use?是什么决定了要使用哪个索引“pip”?
【发布时间】:2017-03-07 18:53:33
【问题描述】:

我希望 pip 从我的驾驶室安装轮子,并回退到 PyPI(通过缓存代理)当且仅当轮子从驾驶室中丢失。

我试图通过调用来实现这一点

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

然而,尽管 Wheelhouse 拥有所有必需的包,但它在从何处获取包似乎相当随机,代理 PyPI 或操舵室。

我希望这是确定性的,并且始终首先选择操舵室。如何使用pip 实现这一目标?

我知道--no-index 会强制它仅使用操舵室,但我想保留对操舵室丢失的包裹进行后备的能力。

【问题讨论】:

标签: python pip python-wheel


【解决方案1】:

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

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

        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. 索引网址
    3. 查找链接网址
    4. 依赖链接 URL

从 pip 9.0.1 开始,上述命令是硬编码的,因此无法使用设置或参数来更改它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多