ERROR: pip’s dependency resolver does not currently take into 报错-Python项目依赖冲突的解决方案-优雅草优雅草卓伊凡
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.
gradio 4.21.0 requires numpy~=1.0, but you have numpy 2.2.6 which is incompatible.
Successfully installed llvmlite-0.45.0 numba-0.62.0 numpy-2.2.6 opencv-python-headless-4.12.0.88 platformdirs-4.4.0 pooch-1.8.2 pymatting-1.1.14 rembg-2.0.67
请按任意键继续. . .
这是完成报错,我们也可以举一反三
这个错误是 依赖冲突,主要是因为 numpy
版本不兼容导致的。虽然显示安装”成功”,但运行时很可能会出现问题。
让我为您提供几种解决方案:
方案一:最稳妥的解决方案(推荐)
创建一个干净的虚拟环境来重新安装,这样可以避免与其他包的版本冲突。
步骤:
- 打开命令提示符(CMD)或 PowerShell
- 创建新的虚拟环境
python -m venv lama-cleaner-env
- 激活虚拟环境
- 在 CMD 中:
lama-cleaner-env\Scripts\activate
- 在 PowerShell 中:
.\lama-cleaner-env\Scripts\Activate.ps1
激活后,命令行前面会显示 (lama-cleaner-env)
。
前缀这样显示代表成功激活了
- 升级 pip
python -m pip install --upgrade pip
升级pip 提示我 有个版本需要升级
执行
python.exe -m pip install —upgrade pip
可以升级,但是我们不升级。
- 安装兼容的 numpy 版本
pip install "numpy<2"
- 安装 Lama Cleaner
- 对于 CPU:
pip install lama-cleaner
- 对于 GPU:
pip install lama-cleaner[gpu]
可以正确安装了,目的达到,本文推荐就是 创建虚拟环境安装,不影响其他项目,至于为什么,卓伊凡单独还有一篇讲解。
方案二:强制安装兼容版本
如果不想创建虚拟环境,可以尝试强制安装兼容的依赖:
pip install "numpy~=1.0" lama-cleaner
或者先降级 numpy,再安装:
pip install "numpy==1.26.4" pip install lama-cleaner
方案三:使用 conda(如果你安装了 Anaconda 或 Miniconda)
# 创建新环境 conda create -n lama-cleaner python=3.10 conda activate lama-cleaner # 安装 pip install lama-cleaner
验证安装是否成功
安装完成后,运行以下命令测试:
lama-cleaner --help
如果正常显示帮助信息,说明安装成功。
运行 Lama Cleaner
# 使用 CPU lama-cleaner --device cpu --port 8080 # 使用 GPU(如果有 NVIDIA 显卡) lama-cleaner --device cuda --port 8080
然后在浏览器中访问:http://localhost:8080
问题原因说明
这个错误的原因是:
gradio
(Lama Cleaner 的 Web 界面依赖)需要 numpy 版本 ~1.0- 但你环境中安装的是 numpy 2.2.6
- 虽然 pip 强制安装了,但版本不兼容可能导致运行时错误
强烈推荐使用方案一(虚拟环境),这样可以完全隔离依赖,避免影响系统中的其他 Python 项目。
针对虚拟环境我单独写了一篇分析