importing tensorrt gives module not found error

798 Views Asked by At

The import of tenosrrt gives an error of module not found. Here are some commands I ran on my terminal. I am working on jetson xavier nx developer tool kit. Tensorrt is installed by default with jetpack flash Python version:3.8 tensorrt version: tensorrt (8.5.2.2-1+cuda11.4) Device: Jetson Xavier NX

$ dpkg -L tensorrt

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/tensorrt
/usr/share/doc/tensorrt/changelog.Debian
/usr/share/doc/tensorrt/copyright

$ sudo apt-get install tensorrt

Reading package lists... Done Building dependency tree Reading state information... Done **tensorrt is already the newest version (8.5.2.2-1+cuda11.4)**. 0 upgraded, 0 newly installed, 0 to remove and 205 not upgraded.

$ python Python 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorrt

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'tensorrt'

I have tried solutions from ImportError: No module named 'tensorrt'

$ pip install nvidia-tensorrt Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting nvidia-tensorrt Downloading nvidia-tensorrt-0.0.1.dev5.tar.gz (7.9 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [17 lines of output] Traceback (most recent call last): File "", line 2, in File "", line 34, in File "/tmp/pip-install-19tykmvn/nvidia-tensorrt_b3ad27f5428d46f594cd069dee9419ee/setup.py", line 150, in raise RuntimeError(open("ERROR.txt", "r").read()) RuntimeError: The package you are trying to install is only a placeholder project on PyPI.org repository. This package is hosted on NVIDIA Python Package Index.

  This package can be installed as:

``` $ pip install nvidia-pyindex $ pip install nvidia-tensorrt ```

  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed

× Encountered error while generating package metadata. ╰─> See above for output.

note: This is an issue with the package mentioned above, not pip. hint: See above for details.

2

There are 2 best solutions below

0
On
0
On

On my Jetson Xavier NX with Jetpack installed

$ python3 -c "import tensorrt as trt; print(trt.__path__)"
['/usr/lib/python3.8/dist-packages/tensorrt']
$ dpkg -S /usr/lib/python3.8/dist-packages/tensorrt
python3-libnvinfer: /usr/lib/python3.8/dist-packages/tensorrt

So you should install python3-libnvinfer to get tensorrt module in Python.