如何解决TensorRT安装过程中的依赖冲突问题
TensorRT安装依赖冲突解决方案
问题背景
安装TensorRT时遭遇系统包依赖冲突,具体错误如下:
安装tensorrt时的错误
The following packages have unmet dependencies: tensorrt : Depends: libnvinfer8 (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvinfer-plugin8 (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvparsers8 (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvonnxparsers8 (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvinfer-bin (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvinfer-dev (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvinfer-plugin-dev (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvparsers-dev (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvonnxparsers-dev (= 8.6.1.6-1+cuda11.8) but it is not going to be installed Depends: libnvinfer-samples (= 8.6.1.6-1+cuda11.8) but it is not going to be installed E: Unable to correct problems, you have held broken packages
安装libnvinfer8时的关键错误
libnvinfer8 : Depends: libcublas.so.11 but it is not installable or libcublas-11-1 but it is not installable or libcublas-11-0 but it is not installable E: Unable to correct problems, you have held broken packages
本地环境说明:
- 已安装CUDA11.2,
libcublas.so.11文件存在于/usr/local/cuda/lib64目录,且已配置LD_LIBRARY_PATH nvcc --version输出为CUDA11.2版本
核心原因
你尝试安装的TensorRT 8.6.1是针对CUDA11.8编译的版本,与本地CUDA11.2不兼容。apt的依赖检查仅识别系统包管理中的库文件,不认可手动放置或CUDA本地安装的库,因此触发依赖错误。
解决步骤
1. 安装与CUDA11.2匹配的TensorRT版本
TensorRT与CUDA版本存在严格对应关系,CUDA11.2兼容的TensorRT版本为8.2.x、8.4.x(例如8.2.3.0、8.4.3.1)。
- 若使用apt安装:
确保已添加NVIDIA官方源后,指定版本安装:sudo apt-get install tensorrt=8.2.3.0-1+cuda11.2 sudo apt-get install python3-libnvinfer=8.2.3.0-1+cuda11.2 - 若找不到对应apt包,可下载对应版本的
.deb包,用以下命令安装:sudo dpkg -i tensorrt_8.2.3.0-1+cuda11.2_amd64.deb sudo apt-get -f install
2. 用pip安装TensorRT(Python环境推荐)
直接通过pip安装TensorRT Python包,避开apt的系统级依赖检查:
pip install tensorrt==8.6.1 --extra-index-url https://pypi.nvidia.com
安装完成后,确保LD_LIBRARY_PATH包含/usr/local/cuda/lib64即可正常使用。
3. 手动解压TensorRT tar包配置
若上述方法不适用,可下载对应CUDA11.2的TensorRT tar包:
- 解压到指定目录,例如
/opt/tensorrt:tar -xzf TensorRT-8.2.3.0.Linux.x86_64-gnu.cuda-11.2.cudnn8.2.tar.gz -C /opt/ - 添加环境变量:
export PATH=/opt/tensorrt/bin:$PATH export LD_LIBRARY_PATH=/opt/tensorrt/lib:$LD_LIBRARY_PATH - 安装Python包:
pip install /opt/tensorrt/python/tensorrt-8.2.3.0-cp37-none-linux_x86_64.whl
4. 修复系统损坏的包依赖
先清理并修复系统包依赖,再重新安装:
sudo apt-get clean sudo apt-get autoclean sudo apt-get update sudo apt-get -f install sudo dpkg --configure -a
内容的提问来源于stack exchange,提问作者Rajesh Gupta
相关产品推荐
相关产品推荐

