ImportError: No module named 'tensorrt'
Asked Answered
B

5

13

I installed TensorRT on my VM using the Debian Installation. If I run "dpkg -l | grep TensorRT" I get the expected result:

ii  graphsurgeon-tf                                             5.0.2-1+cuda10.0                           amd64        GraphSurgeon for TensorRT package
ii  libnvinfer-dev                                              5.0.2-1+cuda10.0                           amd64        TensorRT development libraries and headers
ii  libnvinfer-samples                                          5.0.2-1+cuda10.0                           all          TensorRT samples and documentation
ii  libnvinfer5                                                 5.0.2-1+cuda10.0                           amd64        TensorRT runtime libraries
ii  python3-libnvinfer                                          5.0.2-1+cuda10.0                           amd64        Python 3 bindings for TensorRT
ii  python3-libnvinfer-dev                                      5.0.2-1+cuda10.0                           amd64        Python 3 development package for TensorRT
ii  tensorrt                                                    5.0.2.6-1+cuda10.0                         amd64        Meta package of TensorRT
ii  uff-converter-tf                                            5.0.2-1+cuda10.0                           amd64        UFF converter for TensorRT package

Yet when I try to import it in python I get:

File "<stdin>", line 1, in <module>
ImportError: No module named 'tensorrt'

What am I doing wrong?

Bethannbethanne answered 7/4, 2019 at 10:24 Comment(7)
Are you trying to import in python 2 or python 3?Saltatory
I'm using python 3Bethannbethanne
Please try importing uff, and tensorflow before tensorRT.Saltatory
Was your problem solved?Saltatory
Don't have the environment to test it on anymore, but at the time when I imported uff it wasn't foundBethannbethanne
Me too on the same boat. Installed everything, with dpkg -l | grep TensorRT, I can see python package installed, too but doesn't show up.Edroi
Same here. What version of python3 are you running?Stenotypy
C
9

just run these commands:

pip install nvidia-pyindex
pip install nvidia-tensorrt
Cheviot answered 14/12, 2021 at 9:37 Comment(1)
This solved the problem for me. Thank youInheritance
S
4

i had same error, solved it by installing following 2 packages:

# from TensorRT Tar Package ( TensorRT-5.0.2.6/python/ ) 
pip3 install tensorrt-5.0.2.6-py2.py3-none-any.whl  
# pycuda
pip3 install pycuda 

# libnvinfer 5.0.2-1
# libnvinfer-dev 5.0.2-1
# libnvinfer-samples 5.0.2-1
# python3-libnvinfer 5.0.2-1
# python3-libnvinfer-dev 5.0.2-1
# tensorrt 5.0.2.6
Spithead answered 6/12, 2019 at 5:20 Comment(0)
G
2

two suggestions:

  1. make sure that your TensorRT is added do your path (LD_LIBRARY_PATH)
  2. if you have both python 2 and python3 installed, check for package installation in pip list and/or pip3 list
Gnatcatcher answered 1/8, 2019 at 21:1 Comment(0)
S
1

If you are in a virtual environment, go to the following path to check if it exists.

(deepNN) agxxavier@agxxavier-desktop:~/miniforge3/envs/deepNN/lib/python3.6/site-packages$ ls

Use the following command to check where tensorrt.so is located

(base) agxxavier@agxxavier-desktop:~$ sudo find / -iname "*tensorrt*"

and to create a soft connection in your virtual environment.

(deepNN) agxxavier@agxxavier-desktop:~/miniforge3/envs/deepNN/lib/python3.6/site-packages$ ln -s /usr/lib/python3.6/dist-packages/tensorrt/tensorrt.so tensorrt.so
Sonnnie answered 1/3, 2022 at 18:11 Comment(0)
S
0

You need to import in python3 environment as you seems to have installed TensorRT for python3. So it does not get import on python2.

Silva answered 29/8, 2020 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.