安装过程中遇到 pip 的依赖包和新安装的包有冲突

2024-01-02  本文已影响0人  黄军雷

现象

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchaudio 2.1.0 requires torch==2.1.0, but you have torch 2.1.2 which is incompatible.
torchvision 0.16.0 requires torch==2.1.0, but you have torch 2.1.2 which is incompatible.
xformers 0.0.22.post7 requires torch==2.1.0, but you have torch 2.1.2 which is incompatible.

候选方案

这个错误信息告诉我们,正在尝试安装的某些Python包(torchaudio, torchvision, xformers)与已经安装的torch版本不兼容。具体来说,这些包需要的是torch版本2.1.0,但安装的torch版本是2.1.2。

为了解决这个问题,我们有几个选项:

  1. 降级torch的版本:可以尝试将torch的版本降级到2.1.0,这样就可以与这些包兼容。可以使用以下命令来降级torch的版本:
pip install torch==2.1.0

然后,尝试再次安装这些包。

  1. 升级这些包的版本:有些时候,这些包可能已经有了新版本,这些新版本可能支持你当前的torch版本。可以尝试升级这些包,然后再试一次:
pip install --upgrade torchaudio torchvision xformers
  1. 创建一个虚拟环境:如果经常遇到这种依赖冲突的问题,可以考虑使用虚拟环境。这样,可以为每个项目创建一个独立的环境,每个环境都有自己的库版本。以下是如何使用conda创建虚拟环境的步骤:
conda create -n myenv python=3.8  
conda activate myenv

然后,在这个环境中安装需要的包和torch的2.1.0版本。

我验证后的方案

pip install --upgrade torchaudio torchvision xformers
上一篇下一篇

猜你喜欢

热点阅读