TensorRT-5.0.2.6 | ImportError: /usr/local/lib/python3.5/dist-packages/tensorrt/tensorrt.so: cannot ...

I am running ubuntu 16.04 and have installed tensorrt using tar file TensorRT-5.0.2.6.Ubuntu-16.04.4.x86_64-gnu.cuda-9.0.cudnn7.3.tar.gz.

When I am trying to import tensorrt and I am receiving the below error on Jetson TX2 device-

nvidia@tegra-ubuntu:~$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorrt as trt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/tensorrt/__init__.py", line 1, in <module>
    from .tensorrt import *
ImportError: /usr/local/lib/python3.5/dist-packages/tensorrt/tensorrt.so: cannot open shared object file: No such file or directory

I could see tensorrt.so file also.

nvidia@tegra-ubuntu:/usr/local/lib/python3.5/dist-packages/tensorrt$ ls -lrt
total 2276
-rw-r--r-- 1 root staff    3092 Jan  9 13:16 __init__.py
-rwxr-xr-x 1 root staff 1146544 Jan  9 13:16 tensorrt.cpython-35m-x86_64-linux-gnu.so
-rwxr-xr-x 1 root staff 1171120 Jan  9 13:16 tensorrt.so
drwxr-sr-x 2 root staff    4096 Jan  9 13:16 __pycache__
drwxr-sr-x 7 root staff    4096 Jan  9 13:16 legacy

Already tried setting LD_LIBRARY_PATH path.

nvidia@tegra-ubuntu:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-9.0/lib64:/home/nvidia/TensorRT-5.0.2.6/lib

Cuda toolkit version.

nvidia@tegra-ubuntu:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Sun_Nov_19_03:16:56_CST_2017
Cuda compilation tools, release 9.0, V9.0.252

Any leads to resolve this error will be helpful. Thanks in advance!

Looks good. Just confirming that you’ve completed steps 6 and 7 in Installation Guide :: NVIDIA Deep Learning TensorRT Documentation?

yes, all the steps were performed as mentioned in installation guide including 6 to 8.

  1. Install the Python TensorRT wheel file.
$ sudo pip3 install tensorrt-5.x.x.x-py2.py3-none-any.whl
  1. Install the Python UFF wheel file. This is only required if you plan to use TensorRT with TensorFlow.
$ sudo pip3 install uff-0.5.5-py2.py3-none-any.whl
  1. Install the Python graphsurgeon wheel file.
$ sudo pip3 install graphsurgeon-0.3.2-py2.py3-none-any.whl

Not sure what is causing this issue “ImportError: /usr/local/lib/python3.5/dist-packages/tensorrt/tensorrt.so: cannot open shared object file: No such file or directory

OK. we are trying to repro locally now

I wasn’t able to reproduce this. Can you re-install and send the full output like below?

kschlichter@nvesstation:~$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/kschlichter/TensorRT-5.0.2.6/lib
kschlichter@nvesstation:~$ cd TensorRT-5.0.2.6/python/

kschlichter@nvesstation:~/TensorRT-5.0.2.6/python$ sudo pip2 install tensorrt-5.0.2.6-py2.py3-none-any.whl 
The directory '/home/kschlichter/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/kschlichter/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./tensorrt-5.0.2.6-py2.py3-none-any.whl
Collecting numpy (from tensorrt==5.0.2.6)
  Downloading https://files.pythonhosted.org/packages/de/37/fe7db552f4507f379d81dcb78e58e05030a8941757b1f664517d581b5553/numpy-1.15.4-cp27-cp27mu-manylinux1_x86_64.whl (13.8MB)
    100% |████████████████████████████████| 13.8MB 120kB/s 
Installing collected packages: numpy, tensorrt
Successfully installed numpy-1.15.4 tensorrt-5.0.2.6
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

kschlichter@nvesstation:~/TensorRT-5.0.2.6/python$ sudo pip3 install tensorrt-5.0.2.6-py2.py3-none-any.whl 
The directory '/home/kschlichter/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/kschlichter/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./tensorrt-5.0.2.6-py2.py3-none-any.whl
Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages (from tensorrt==5.0.2.6) (1.15.2)
Installing collected packages: tensorrt
Successfully installed tensorrt-5.0.2.6

kschlichter@nvesstation:~/TensorRT-5.0.2.6/python$ cd ../uff/

kschlichter@nvesstation:~/TensorRT-5.0.2.6/uff$  sudo pip3 install uff-0.5.5-py2.py3-none-any.whl 
The directory '/home/kschlichter/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/kschlichter/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./uff-0.5.5-py2.py3-none-any.whl
Collecting protobuf>=3.3.0 (from uff==0.5.5)
  Downloading https://files.pythonhosted.org/packages/bf/d4/db7296a1407cad69f043537ba1e05afab3646451a066ead7a314d8714388/protobuf-3.6.1-cp35-cp35m-manylinux1_x86_64.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 25.9MB/s 
Requirement already satisfied: numpy>=1.11.0 in /usr/local/lib/python3.5/dist-packages (from uff==0.5.5) (1.15.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.5/dist-packages (from protobuf>=3.3.0->uff==0.5.5) (39.0.1)
Requirement already satisfied: six>=1.9 in /usr/local/lib/python3.5/dist-packages (from protobuf>=3.3.0->uff==0.5.5) (1.11.0)
Installing collected packages: protobuf, uff
Successfully installed protobuf-3.6.1 uff-0.5.5

kschlichter@nvesstation:~/TensorRT-5.0.2.6/uff$ which convert-to-uff
/usr/local/bin/convert-to-uff

kschlichter@nvesstation:~/TensorRT-5.0.2.6/uff$ cd ../graphsurgeon/

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ sudo pip3 install graphsurgeon-0.3.2-py2.py3-none-any.whl
The directory '/home/kschlichter/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/kschlichter/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./graphsurgeon-0.3.2-py2.py3-none-any.whl
Installing collected packages: graphsurgeon
Successfully installed graphsurgeon-0.3.2

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorrt as trt
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
>>> 

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/te
tensorrt/                   tensorrt-5.0.2.6.dist-info/ terminado/                  terminado-0.8.1.dist-info/  testpath/                   testpath-0.3.1.dist-info/   

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/tensorrt
tensorrt/                   tensorrt-5.0.2.6.dist-info/ 

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/tensorrt/
__init__.py  legacy  __pycache__  tensorrt.cpython-35m-x86_64-linux-gnu.so  tensorrt.so

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/tensorrt/ -lh
total 2.3M
-rw-r--r-- 1 root staff 3.1K Jan  9 13:29 __init__.py
drwxr-sr-x 7 root staff 4.0K Jan  9 13:29 legacy
drwxr-sr-x 2 root staff 4.0K Jan  9 13:29 __pycache__
-rwxr-xr-x 1 root staff 1.1M Jan  9 13:29 tensorrt.cpython-35m-x86_64-linux-gnu.so
-rwxr-xr-x 1 root staff 1.2M Jan  9 13:29 tensorrt.so

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ echo $LD_LIBRARY_PATH
:/home/kschlichter/TensorRT-5.0.2.6/lib

kschlichter@nvesstation:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/tensorrt/ -lrt
total 2276
-rw-r--r-- 1 root staff    3092 Jan  9 13:29 __init__.py
-rwxr-xr-x 1 root staff 1146544 Jan  9 13:29 tensorrt.cpython-35m-x86_64-linux-gnu.so
-rwxr-xr-x 1 root staff 1171120 Jan  9 13:29 tensorrt.so
drwxr-sr-x 2 root staff    4096 Jan  9 13:29 __pycache__
drwxr-sr-x 7 root staff    4096 Jan  9 13:29 legacy

Hi KevinSchlichter

Did you try to install TRT 5.0.2.6 on Jetson TX2 board ?

Because this contradicts the below comment made by AastaLLL.

https://devtalk.nvidia.com/default/topic/1044025/jetson-tx2/how-to-install-tensorrt-5-on-tx2-/

Hi KevinSchlichte,

Thanks for the quick response.

I have reflashed the Jetson TX2 board, and please find the full installation logs for TensorRT-5.0.2.6 on TX2 device.

nvidia@tegra-ubuntu:~$ export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/home/nvidia/TensorRT-5.0.2.6/lib 
nvidia@tegra-ubuntu:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-9.0/lib64:/home/nvidia/TensorRT-5.0.2.6/lib
nvidia@tegra-ubuntu:~$ cd TensorRT-5.0.2.6/python/
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/python$ sudo pip3 install tensorrt-5.0.2.6-py2.py3-none-any.whl
[sudo] password for nvidia: 
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./tensorrt-5.0.2.6-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): numpy in /home/nvidia/.local/lib/python3.5/site-packages (from tensorrt==5.0.2.6)
Installing collected packages: tensorrt
Successfully installed tensorrt-5.0.2.6
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/python$ cd ../uff/
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/uff$ sudo pip3 install uff-0.5.5-py2.py3-none-any.whl
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./uff-0.5.5-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11.0 in /home/nvidia/.local/lib/python3.5/site-packages (from uff==0.5.5)
Requirement already satisfied (use --upgrade to upgrade): protobuf>=3.3.0 in /home/nvidia/.local/lib/python3.5/site-packages (from uff==0.5.5)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /home/nvidia/.local/lib/python3.5/site-packages (from protobuf>=3.3.0->uff==0.5.5)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9 in /home/nvidia/.local/lib/python3.5/site-packages (from protobuf>=3.3.0->uff==0.5.5)
Installing collected packages: uff
Successfully installed uff-0.5.5
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/uff$ which convert-to-uff
/usr/local/bin/convert-to-uff
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/uff$ cd ../graphsurgeon/
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/graphsurgeon$ sudo pip3 install graphsurgeon-0.3.2-py2.py3-none-any.whl
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Processing ./graphsurgeon-0.3.2-py2.py3-none-any.whl
Installing collected packages: graphsurgeon
Successfully installed graphsurgeon-0.3.2
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/graphsurgeon$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorrt as trt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/tensorrt/__init__.py", line 1, in <module>
    from .tensorrt import *
ImportError: /usr/local/lib/python3.5/dist-packages/tensorrt/tensorrt.so: cannot open shared object file: No such file or directory
>>> 
[1]+  Stopped                 python3
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/graphsurgeon$ ls /usr/local/lib/python3.5/dist-packages/tensorrt/ -lrt
total 2276
-rw-r--r-- 1 root staff    3092 Jan 10 10:02 __init__.py
-rwxr-xr-x 1 root staff 1146544 Jan 10 10:02 tensorrt.cpython-35m-x86_64-linux-gnu.so
-rwxr-xr-x 1 root staff 1171120 Jan 10 10:02 tensorrt.so
drwxr-sr-x 2 root staff    4096 Jan 10 10:02 __pycache__
drwxr-sr-x 7 root staff    4096 Jan 10 10:02 legacy
nvidia@tegra-ubuntu:~/TensorRT-5.0.2.6/graphsurgeon$ cd 
nvidia@tegra-ubuntu:~$ echo $LD_LIBRARY_PATH
/usr/local/cuda-9.0/lib64:/home/nvidia/TensorRT-5.0.2.6/lib
nvidia@tegra-ubuntu:~$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorrt as trt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/tensorrt/__init__.py", line 1, in <module>
    from .tensorrt import *
ImportError: /usr/local/lib/python3.5/dist-packages/tensorrt/tensorrt.so: cannot open shared object file: No such file or directory
>>>

Could you please let me know where did you tried to reproduce this error? Is it Jetson TX2 device?

Also refer to the link commented above by @varun365.

Let me know if you need any specific info. to debug this further.

I’m moving this to the Jetson / TX2 forum for help.

Hi,

TensorRT Python API doesn’t support Jetson platform yet.
You can find our support matrix here:
[url]Support Matrix :: NVIDIA Deep Learning TensorRT Documentation

Thanks.