到目前为止,我使用了(viaHow to upgrade all Python packages with pip)
pip3 list --format freeze --outdated | cut -d= -f1 | xargs pip3 install --upgrade-strategy eager --upgrade
升级我的所有Python pip包。到目前为止,它对我来说效果很好——除了有一次,当我收到一条有冲突的信息时,不幸的是我没有保留它的副本;我的猜测是,这与这里提到的https://pip.pypa.io/en/stable/user_guide/#fixing-conflicting-dependencies类似:
Due to conflicting dependencies pip cannot install
package_coffee and package_tea:
- package_coffee depends on package_water<3.0.0,>=2.4.2
- package_tea depends on package_water==2.3.1
无论如何,现在我只是尝试为我的Jupyter安装安装voila
,结果是这样的:
(notebook) user@server:/home/web/Jupyter$ pip3 install voila
...
Installing collected packages: jupyter-client, voila
Attempting uninstall: jupyter-client
Found existing installation: jupyter-client 7.0.3
Uninstalling jupyter-client-7.0.3:
Successfully uninstalled jupyter-client-7.0.3
Successfully installed jupyter-client-6.1.12 voila-0.2.13
换句话说:我已经安装了jupyter-client-7.0.3
作为最新版本;但是现在我想安装voila
,由于voila
的要求,最新版本被卸载了,而与voila
兼容的早期版本6.1.12
被安装了
因此,现在如果我想检查过时的包,我会像预期的那样,列出jupyter-client
:
(notebook) user@server:/home/web/Jupyter$ pip3 list --format freeze --outdated
jupyter-client==6.1.12
。。。但是,如果我运行full-pipe命令pip3 list --format freeze --outdated | cut -d= -f1 | xargs pip3 install --upgrade-strategy eager --upgrade
,那么它会想将jupyter-client
升级到7.0.3,然后会中断voila
(我想,我不敢尝试)
那么,是否有一个升级命令,它将采取这样的情况,并在升级过程中出现这种状态时,阻止更改并通知我?比如说:
WARNING: There is an upgrade to jupyter-client=6.1.12 (newest version 7.0.3) - however, installing that package would cause a conflict with the currently installed
voila=0.2.13
package; not proceeding with this upgrade. To force this upgrade regardless, use [...]
由于重叠(子)依赖关系,在python中升级包从来都不容易。有一些工具可以尝试帮助您进行管理。在我目前的工作中,我们使用pip-tools。在一些项目中,我们使用poetry,但我对它的处理不太满意
对于pip工具,您可以在
requirements.in
文件中定义顶级包,然后解析子(sub-sub)依赖项并将它们输出到requirements.txt
文件中。 这样做的好处是,您只需要担心您的主要软件包。 如果需要,您仍然可以升级子依赖项长话短说;盲目更新所有您的软件包很可能永远不会按预期或预期运行。要么软件包已升级但停止工作,要么它们可以工作但不能与另一个已更新的软件包一起工作,因为它们需要该软件包的较低版本
我的建议是从您的主要软件包开始,然后使用上面提到的工具之一进行构建。这件事没有灵丹妙药。依赖地狱在python中是一个非常真实的东西
相关问题 更多 >
编程相关推荐