1.查看CUDA、Ubuntu和Python版本
!nvcc -V #查看cuda版本
!lsb_release -a #查看ubuntu版本
!python --version #查看python版本
当前Colab的版本为cuda11.0,Ubuntu18.04,python3.7
2.下载Tensor RT安装包
下载网址,需要注册账户,找到对应的安装包,DEB和TAR两个都需要下载
3.安装
-
将下载的nv-tensorrt-repo-ubuntu1804-cuda11.0-trt7.2.3.4-ga-20210226_1-1_amd64.deb上传至谷歌云盘的任意位置
-
#解压安装 !sudo dpkg -i "/content/drive/tensorrt/nv-tensorrt-repo-ubuntu1804-cuda11.0-trt7.2.3.4-ga-20210226_1-1_amd64.deb" !sudo apt-key add /var/nv-tensorrt-repo-ubuntu1804-cuda11.0-trt7.2.3.4-ea-20210226/7fa2af80.pub !sudo apt-get update
-
# 安装依赖包(依赖包可以根据报错提示自行修改) !sudo apt-get install libnvinfer7=7.2.3-1+cuda11.0 libnvinfer-plugin7=7.2.3-1+cuda11.0 libnvparsers7=7.2.3-1+cuda11.0 libnvonnxparsers7=7.2.3-1+cuda11.0 libnvinfer-bin=7.2.3-1+cuda11.0 libnvinfer-dev=7.2.3-1+cuda11.0 libnvinfer-plugin-dev=7.2.3-1+cuda11.0 libnvparsers-dev=7.2.3-1+cuda11.0 libnvonnxparsers-dev=7.2.3-1+cuda11.0 libnvinfer-samples=7.2.3-1+cuda11.0 libnvinfer-doc=7.2.3-1+cuda11.0 !sudo apt-mark hold libnvinfer7 libnvinfer-plugin7 libnvparsers7 libnvonnxparsers7 libnvinfer-bin libnvinfer-dev libnvinfer-plugin-dev libnvparsers-dev libnvonnxparsers-dev libnvinfer-samples libnvinfer-doc !sudo apt-get install tensorrt #安装pycuda !pip install pycuda
其实到这一步就安装成功了,可以运行!dpkg -l | grep TensorRT
测试一下
但这时候import tensorrt
的话,会发现还是会报错no module named tensorrt
,接下来解决这个问题。解压第一步中下载的tar文件,在python文件夹中找到tensorrt-7.2.3.4-cp37-none-linux_x86_64.whl
(注意核对python版本),将其上传至谷歌云盘,然后pip安装!pip install /content/drive/tensorrt/tensorrt-7.2.3.4-cp37-none-linux_x86_64.whl
再import tensorrt
测试一下,问题解决,安装成功
https://blog.csdn.net/KongCDY/article/details/100082712