Error importing Logger attribute in python

Description

Hi,

I’m trying to do model inference in my Jetson Nano. I have a pretrained ResNet50 in onnx format that I want to read with TensorRT. My code just does:

import tensorrt as trt

TRT_LOGGER = trt.Logger(trt.Logger.WARNING)

But get the following exception:

AttributeError: module ‘tensorrt’ has no attribute ‘Logger’

The installation of TensorRT that I’m using is the one that comes prinstalled in Jetson Nano

Should I delete and reinstall it, or am I doing something wrong?

Thanks in advance.

Environment

TensorRT Version: 7.1.3
GPU Type: 128-core Maxwell
CUDA Version: 10.2.89
CUDNN Version: 8.0.0
Operating System + Version: Ubuntu 18.04.5 LTS (Jetson Nano)
Python Version (if applicable): 3.6.9

Hi @imartgarr,

We recommend you to reinstall the tensorrt.
For your reference,

Thank you.

@spolisetty I am also facing exactly same issue and i have also tried uninstalling TensorRT and Installing again but no luck. Any idea why?
I am sucessufully able to import tensorrt as trt but i have no idea why Looger module is not found.

import io, os
import logging
import tensorrt as trt
import time
from PIL import Image
import numpy as np
import pycuda.driver as cuda
import pycuda.autoinit

def load_engine(trt_runtime, engine_path):
    #trt.init_libnvinfer_plugins(None, "") 
    with open(engine_path, 'rb') as f:
        engine_data = f.read()
    engine = trt_runtime.deserialize_cuda_engine(engine_data)
    return engine

#TRT_LOGGER = logging.debug('This is a debug message')
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
trt_runtime = trt.Runtime(TRT_LOGGER)
trt_engine_path = "/home/adas/samples/my_engine.trt"
trt_engine = load_engine(trt_runtime, trt_engine_path)

if trt_engine is not None:
    print("Success")                                      
else:
    print("Failed")
Traceback (most recent call last):
  File "./nvidia_inference.py", line 19, in <module>
    TRT_LOGGER = trt.Logger(trt.Logger.INFO)
AttributeError: module 'tensorrt' has no attribute 'Logger'

TensorRT Version : 8.2
GPU Type : Quadro RTX 5000
Nvidia Driver Version :470.42.01
CUDA Version : 11.4

I have encountered this error too.

I am working on a Jetson Nano B01 with:
-JetPack 4.6 [L4T 32.6.1]
-CUDA 10.2.300 (preinstalled)
-cuDNN 8.2.1.32 (preinstalled)
-TensorRT 8.0.1.6 (preinstalled)
-Python 3.6.9 in a virtual environment

I have created a symbolic link to the preinstalled version of TensorRT with the following command:
sudo ln -s /usr/lib/python3.6/dist-packages/tensorrt ~/Public/Projects/myPython36VEnv/lib/python3.6/site-packages/tensorrt

My Python program is simply:

import tensorrt as trt
TRT_LOGGER = trt.Logger()

The output is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-b4acf9015a93> in <module>
      1 import tensorrt as trt
----> 2 TRT_LOGGER = trt.Logger()

AttributeError: module 'tensorrt' has no attribute 'Logger'

I see from previous posts that the suggested solution is to reinstall TensorRT, however,I read that someone has tried this and it did not solve the problem.

I have found reports of this error on a few other websites but a solution is never provided.

I would be grateful for any suggestions.

I have found the answer…

When trying to debug, I found that not even the version command worked in my virtual environment:

import tensorrt as trt
print(trt.__version__)

The answer is at this link:
https://forums.developer.nvidia.com/t/attributeerror-module-tensorrt-has-no-attribute-version/213882/4

The answer, directly copied from the above link is:

I copied the sub directories about tensorrt under /usr/lib/python3.6/dist-packages/
to my virtual environment ~/py3/lib/python3.6/site-packages/

I copied these sub directories over:
-tensorrt
-tensorrt-8.0.1.6.dist-infotensorrt-8.0.1.6.dist-info
-uff
-uff-0.6.9.dist-info
-graphsurgeon
-graphsurgeon-0.4.5.dist-info

Problem solved.