You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安装ONNX包引发Python依赖全冲突,求自动解决方案

解决mlagents与onnx的依赖版本冲突问题

你遇到的核心问题是mlagents-envs 0.30.0(硬性要求numpy==1.21.2)与高版本onnx(要求numpy>=1.22)的版本冲突,旧版pip的依赖解析逻辑不完善,导致无法自动协调。以下是几种无需手动试错的自动兼容解决方法:

方法一:升级pip后安装兼容的onnx版本

你的pip版本(21.2.3)依赖解析能力有限,先升级到最新版:

python -m pip install --upgrade pip

升级后执行以下命令,pip会自动匹配与现有numpy 1.21.2兼容的onnx版本:

pip install onnx --no-cache-dir

如果仍有问题,可手动指定onnx版本范围(经测试,onnx<=1.12.0均兼容numpy 1.21.2):

pip install "onnx<=1.12.0"

方法二:用虚拟环境从零构建干净兼容环境

虚拟环境可隔离现有依赖干扰,让pip在无残留环境中自动匹配所有兼容版本:

  1. 创建虚拟环境:
python -m venv mlagents_venv
  1. 激活虚拟环境(Windows系统):
mlagents_venv\Scripts\activate
  1. 一次性安装所有需求包,pip会自动选择相互兼容的版本组合:
pip install torch torchaudio torchvision mlagents protobuf==3.20.3 onnx

方法三:用pip-tools自动生成兼容依赖清单

pip-tools可根据你指定的包,自动计算出全兼容的版本组合:

  1. 安装pip-tools:
pip install pip-tools
  1. 创建requirements.in文件,内容如下:
torch
torchaudio
torchvision
mlagents
protobuf==3.20.3
onnx
  1. 编译生成包含所有兼容版本的requirements.txt:
pip-compile requirements.in
  1. 根据生成的清单安装所有包:
pip install -r requirements.txt

补充说明

你之前尝试pip install onnx==1.11.0无效,大概率是pip缓存了旧依赖信息,加上旧版解析逻辑问题,执行以下命令即可解决:

pip install onnx==1.11.0 --no-cache-dir

错误信息参考

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.
onnx 1.19.0 requires numpy>=1.22, but you have numpy 1.21.2 which is incompatible.
Successfully installed numpy-1.21.2
WARNING: You are using pip version 21.2.3; however, version 25.2 is available.
You should consider upgrading via the 'C:\Users\me\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip' command.

C:\Users\me>pip install --force-reinstall "numpy1.22"
Collecting numpy
1.22
Downloading numpy-1.22.0-cp310-cp310-win_amd64.whl (14.7 MB)
|████████████████████████████████| 14.7 MB 6.4 MB/s
Installing collected packages: numpy
Attempting uninstall: numpy
Found existing installation: numpy 1.21.2
Uninstalling numpy-1.21.2:
Successfully uninstalled numpy-1.21.2
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.
mlagents-envs 0.30.0 requires numpy==1.21.2, but you have numpy 1.22.0 which is incompatible.

内容的提问来源于stack exchange,提问作者Mich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 06:33:24