python - 什么决定了将使用哪个索引 `pip`?

标签 python pip python-wheel

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

我试图通过调用

来实现这一 pip
pip install -U --index-url $PYPI_PROXY_URL --find-links $WHEELHOUSE_URL \
            -r requirements.txt

然而,尽管 wheelhouse 拥有所有必需的包,但在包的来源、代理 PyPI 或 wheelhouse 方面似乎非常随机,而不是确定性地从何处获取包。

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

我知道 --no-index 会强制它只使用驾驶室,但我想保留回退驾驶室丢失的包的能力。

最佳答案

深入研究 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. 查找链接 URL
    4. 依赖链接 URL

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

关于python - 什么决定了将使用哪个索引 `pip`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42656047/

相关文章:

python - 如何在用于主题建模的引导式 LDA 中生成术语矩阵?

python - Python Wheels 的条件依赖

django - 错误: invalid command 'bdist_wheel'

python - 不在实时服务器上托管编译器的原因是什么?

heroku - heroku Flask webapp 部署中的requirements.txt vs Pipfile?

python-wheel - 如何使用 Azure Synapse Analytics 将自定义 Python 库导入到 apache Spark 池中?

python - 如何在没有qrc系统的情况下在pyqt6中设置背景图像

python - 在 Python 中递归检查 JSON 对象

python - 在python中,比较元素中的两个数组并将较低的值更改为零

python - tokyo-python 安装问题