ImportError: libnvinfer.so.7: cannot open shared object file

ubuntu18.04 安装完tensorrt7.2.3,在终端调用tensorrt没有问题,但在pycharm里运行时,提示找不到libnvinfer.so.7
虽然在bashrc中设置了环境变量,但是也没有对pycharm起到作用,出现如下报错:

Traceback (most recent call last):
File "/media/lindsay/591d8930-456f-45c2-9059-4e020abd1169/tensorrtx/yolov5/streams_trt.py", line 15, in 
  import tensorrt as trt
File "/home/lindsay/anaconda3/envs/yolov5/lib/python3.8/site-packages/tensorrt/__init__.py", line 66, in 
  from .tensorrt import *
ImportError: libnvinfer.so.7: cannot open shared object file: No such file or directory

为了解决问题,可以在pycharm中设置环境变量:

可以参考bashrc中的路径,执行

sudo  vim ~/.bashrc

提取里面的LD_LIBRARY_PATH以及对应的值

export TRT_PATH=/home/lindsay/TensorRT-7.2.2.3
export PATH=$PATH:$TRT_PATH/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRT_PATH/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TRT_PATH/targets/x86_64-linux-gnu/lib

点击Run—Edit Configurations,然后在Environment variables中点开后添加一个name以及一个value,如下图所示:

ImportError: libnvinfer.so.7: cannot open shared object file_第1张图片
以下为我添加的:

Name:LD_LIBRARY_PATH
Value:/home/lindsay/TensorRT-7.2.2.3/lib

一起开启新世界的大门吧

你可能感兴趣的:(yolov5,linux,深度学习,python,ubuntu,tensorrt)