# Tensorrt on Jetson with python 3.9

**URL:** <https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131>\
**Category:** Jetson Xavier NX\
**Tags:** python, tensorrt\
**Created:** [November 24, 2021, 3:04pm UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131 "2021-11-24T15:04:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![appv](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@appv](https://forums.developer.nvidia.com/u/appv)\
**Post date:** [November 24, 2021, 3:04pm UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/1 "2021-11-24T15:04:26Z")

</div>

Hi,

im following up on [Can TensorRT work on python 3.9 on Jetson AGX Xavier?](https://forums.developer.nvidia.com/t/can-tensorrt-work-on-python-3-9-on-jetson-agx-xavier/192811) and try to get tensorrt to run with python 3.9 on nvidia jetson NX.

As far as i understand i need to build TensorRT OSS ([GitHub - NVIDIA/TensorRT: TensorRT is a C++ library for high performance inference on NVIDIA GPUs and deep learning accelerators.](https://github.com/NVIDIA/TensorRT)) on the jetson in order to run the build script as described in [TensorRT/python at main · NVIDIA/TensorRT · GitHub](https://github.com/NVIDIA/TensorRT/tree/main/python) to create python wheel file.  
Is that the correct approach to get it running?

The first problem i encounter is actually building TensorRT OSS on the jetson, as i need to specify " `TRT_LIB_DIR` : Path to the TensorRT installation directory containing libraries." (see [GitHub - NVIDIA/TensorRT: TensorRT is a C++ library for high performance inference on NVIDIA GPUs and deep learning accelerators.](https://github.com/NVIDIA/TensorRT#building-tensorrt-oss)), which i cannot find. I used the sd-card method to get my jetson running and can only find the preinstalled tensorrt under /usr/src/tensorrt which does not seem to incluce libraries. Am i missing something here?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [November 25, 2021, 3:45am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/3 "2021-11-25T03:45:08Z")

</div>

Hi,

Please install the TensorRT C++ library first and build a python binding for python3.9 from OSS GitHub.  
The TensorRT C++ library can be found in SDK manager or installed via the following command:

```auto
$ sudo apt update
$ sudo apt install nvidia-tensorrt

```

After that, the header and library can be found in the below folder:

```auto
$ ll /usr/include/aarch64-linux-gnu/NvInfer*
-rw-r--r-- 1 root root 268726 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInfer.h
-rw-r--r-- 1 root root 42497 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferImpl.h
-rw-r--r-- 1 root root 6176 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferLegacyDims.h
-rw-r--r-- 1 root root 11327 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferPlugin.h
-rw-r--r-- 1 root root 11819 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferPluginUtils.h
-rw-r--r-- 1 root root 60163 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferRuntimeCommon.h
-rw-r--r-- 1 root root 94791 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferRuntime.h
-rw-r--r-- 1 root root 3148 Jun 25 20:17 /usr/include/aarch64-linux-gnu/NvInferVersion.h

```

```auto
$ ll /usr/lib/aarch64-linux-gnu/libnvinfer*
lrwxrwxrwx 1 root root 26 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so -> libnvinfer_plugin.so.8.0.1
lrwxrwxrwx 1 root root 26 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so.8 -> libnvinfer_plugin.so.8.0.1
-rw-r--r-- 1 root root 18280576 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer_plugin.so.8.0.1
-rw-r--r-- 1 root root 21018654 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer_plugin_static.a
lrwxrwxrwx 1 root root 19 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer.so -> libnvinfer.so.8.0.1
lrwxrwxrwx 1 root root 19 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer.so.8 -> libnvinfer.so.8.0.1
-rw-r--r-- 1 root root 188463744 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer.so.8.0.1
-rw-r--r-- 1 root root 333591900 Jun 25 20:17 /usr/lib/aarch64-linux-gnu/libnvinfer_static.a

```

Thanks.

---

<div class="post-metadata">

**Author:** ![appv](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@appv](https://forums.developer.nvidia.com/u/appv)\
**Post date:** [December 8, 2021, 11:14am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/5 "2021-12-08T11:14:37Z")

</div>

Was able to build TensorRT OSS this way.

However there is a problem gernerating or using the python bindings. Following everything under [https://github.com/NVIDIA/TensorRT/tree/main/python](https://github.com/NVIDIA/TensorRT/tree/main/python) i’m able to create “tensorrt-8.0.1.6-cp39-none-linux\_aarch64.whl” and installing it in a venv with python3 -m pip install build/dist/tensorrt-8.0.1.6-cp39-none-linux\_aarch64.whl succeeds.  
But import tensorrt fails with the following error.

> import tensorrt  
> Traceback (most recent call last):  
> File “”, line 1, in   
> File “path/to/my/venv/lib/python3.9/site-packages/tensorrt/ **init**.py”, line 36, in   
> from .tensorrt import \*  
> ModuleNotFoundError: No module named ‘tensorrt.tensorrt’

the .whl file is only 3.8kb small and running the ./build.sh that generates the .whl file in TensorRT/python also has some suspicious logs:

> – Generating done  
> – Build files have been written to:/path/to/TensorRT/python  
> make: \*\*\* No targets specified and no makefile found. Stop.  
> Generating python 3.9 bindings for TensorRT 8.0.1.6

Any suggestions?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [December 16, 2021, 5:41am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/7 "2021-12-16T05:41:35Z")

</div>

Hi,

Thanks for updating the status with us.

We are going to check this internally.  
Will share more information with you later.

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [December 20, 2021, 5:30am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/9 "2021-12-20T05:30:29Z")

</div>

Hi,

We have confirmed that bindings for python3.9 can be compiled and installed on JetPack4.6.  
Please check the following for the detailed instructions:

### 1. Building python3.9

```auto
$ sudo apt install zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev
$ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
$ tar xvf Python-3.9.1.tar.xz Python-3.9.1/

```

```auto
$ mkdir build-python-3.9.1
$ cd build-python-3.9.1/
$ ../Python-3.9.1/configure --enable-optimizations
$ make -j $(nproc)
$ sudo -H make altinstall
$ cd ../

```

### 2. Build cmake 3.13.5

```auto
$ sudo apt-get install -y protobuf-compiler libprotobuf-dev openssl libssl-dev libcurl4-openssl-dev
$ wget https://github.com/Kitware/CMake/releases/download/v3.13.5/cmake-3.13.5.tar.gz
$ tar xvf cmake-3.13.5.tar.gz
$ rm cmake-3.13.5.tar.gz

```

```auto
$ cd cmake-3.13.5/
$ ./bootstrap --system-curl
$ make -j$(nproc)

```

```auto
$ echo 'export PATH='${PWD}'/bin/:$PATH' >> ~/.bashrc
$ source ~/.bashrc
$ cd ../

```

### 3. Prepare header

```auto
$ mkdir python3.9
$ mkdir python3.9/include
$ wget http://ftp.us.debian.org/debian/pool/main/p/python3.9/libpython3.9-dev_3.9.9-2_arm64.deb
$ ar x libpython3.9-dev_3.9.9-2_arm64.deb
$ tar -xvf data.tar.xz
$ cp ./usr/include/aarch64-linux-gnu/python3.9/pyconfig.h python3.9/include/
$ cp -r Python-3.9.1/Include/* python3.9/include/

```

### 4. Build TensorRT pybinding

```auto
$ git clone https://github.com/pybind/pybind11.git
$ git clone -b release/8.0 https://github.com/NVIDIA/TensorRT.git
$ cd TensorRT
$ git submodule update --init --recursive

```

Please replay _{TensorRT}/python/build.sh_ with this file: [build.sh](https://forums.developer.nvidia.com/uploads/short-url/oOBhYDgezhZl6IIuoIXSTRiZbuj.sh) (2.5 KB)

```auto
$ cd python/
$ TRT_OSSPATH=${PWD}/.. EXT_PATH=${PWD}/../.. ./build.sh
$ python3.9 -m pip install build/dist/tensorrt-8.0.1.6-cp39-none-linux_aarch64.whl

```

Reference:  
[https://arcanesciencelab.wordpress.com/2021/02/14/building-python-3-9-1-on-jetpack-4-5-and-the-jetson-xavier-nx/](https://arcanesciencelab.wordpress.com/2021/02/14/building-python-3-9-1-on-jetpack-4-5-and-the-jetson-xavier-nx/)  
[https://github.com/NVIDIA/TensorRT/tree/main/python](https://github.com/NVIDIA/TensorRT/tree/main/python)

Thanks.

---

<div class="post-metadata">

**Author:** ![appv](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@appv](https://forums.developer.nvidia.com/u/appv)\
**Post date:** [December 20, 2021, 9:22am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/10 "2021-12-20T09:22:22Z")

</div>

It works. I dont know what went wrong before but following your guide with a fresh start solved it.  
Thank you very much for putting the instructions together like that. That’s really awesome support.

Just as a note for others (and probably future me):

For the ./build.sh call (last step) i needed to additionally set the environment variables TARGET=aarch64 and PYTHON\_MINOR\_VERSION=9 in order to get the desired version of the .whl.

Also in 3. Prepare header the “$” in

```auto
tar -xvf data.tar.xz$ cp ./usr/include/aarch64-linux-gnu/python3.9/pyconfig.h python3.9/include/

```

should be a “&&” i guess?

---

<div class="post-metadata">

**Author:** ![AastaLLL](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/aastalll/32/14043_2.png) [@AastaLLL](https://forums.developer.nvidia.com/u/AastaLLL)\
**Post date:** [December 21, 2021, 2:53am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/11 "2021-12-21T02:53:34Z")

</div>

Hi,

Thanks for the feedback.

It should be a newline but connected to the previous line accidentally.  
We have updated the commands and also attach the script for completeness.

Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [January 4, 2022, 2:54am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/12 "2022-01-04T02:54:26Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![kayccc](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kayccc/32/14043_2.png) [@kayccc](https://forums.developer.nvidia.com/u/kayccc)\
**Post date:** [January 12, 2022, 1:23am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/13 "2022-01-12T01:23:04Z")

</div>



---

<div class="post-metadata">

**Author:** ![kayccc](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kayccc/32/14043_2.png) [@kayccc](https://forums.developer.nvidia.com/u/kayccc)\
**Post date:** [January 12, 2022, 1:23am UTC](https://forums.developer.nvidia.com/t/tensorrt-on-jetson-with-python-3-9/196131/15 "2022-01-12T01:23:11Z")

</div>


