我希望 pip
从我的驾驶室安装轮子,并回退到 PyPI(通过缓存代理)当且仅当轮子从驾驶室丢失时。
我试图通过调用
来实现这一 pippip install -U --index-url $PYPI_PROXY_URL --find-links $WHEELHOUSE_URL \
-r requirements.txt
然而,尽管 wheelhouse 拥有所有必需的包,但在包的来源、代理 PyPI 或 wheelhouse 方面似乎非常随机,而不是确定性地从何处获取包。
我希望这是确定性的,并且始终首先选择驾驶室。我如何使用 pip
实现这一 pip ?
我知道 --no-index
会强制它只使用驾驶室,但我想保留回退驾驶室丢失的包的能力。
最佳答案
深入研究 pip 的源代码我发现:
有效候选者使用内部
_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
在其他条件相同的情况下,返回到 hardcoded顺序是:
- 本地文件系统
- 索引网址
- 查找链接 URL
- 依赖链接 URL
从 pip 9.0.1 开始,上述顺序是硬编码的,因此无法使用设置或参数更改它。
关于python - 什么决定了将使用哪个索引 `pip`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42656047/