TensorRT: export failure: No module named 'tensorrt'

我在Base环境里已经安装了TensoRT 8.2.5.1,我准备生成YOLOv5的tensort engine,但是报错TensorRT: export failure: No module named ‘tensorrt’
我的虚拟环境中没有tensorrt,但是我找不到本地tensorrt的安装目录
我想知道如何查找TensorRT的安装目录?

Hi,

Please refer to the following installation guide and make sure TensorRT is installed correctly.

To avoid setup related issues, if you’re interested, you can also use the TensorRT NGC container.
https://ngc.nvidia.com/containers/nvidia:tensorrt

Thank you.

我通过dpkg -l | grep TensorRT命令确定我的TensorRT安装成功了,DeepStream也可以正常运行,但是我无法找到TensorRT安装在哪里

Hi,

Please refer Where is TensorRT located in an Ubuntu 16.04 dpkg installation? - #2 by NVES to get details on where TensorRT is installed.

Thank you.

Hello, I encountered a problem while installing TensorRT on Jetson TX2 with a Python 3.8 environment. The error message is “No module named ‘tensorrt.tensorrt’”. Here are the specific steps I followed. Can you help me solve this issue?

sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev protobuf-compiler libprotobuf-dev libcurl4-openssl-dev
wget https://www.python.org/ftp/python/3.8.19/Python-3.8.19.tar.xz
tar xvf Python-3.8.19.tar.xz -C Python-3.8.19/ --strip-components=1
mkdir build-python-3.8.19
cd build-python-3.8.19/
…/Python-3.8.19/configure --enable-optimizations
make -j $(nproc)
sudo -H make altinstall
sudo apt-get install libpython3.8-dev
mkdir python3.8
mkdir python3.8/include
cp /usr/include/aarch64-linux-gnu/python3.8/pyconfig.h python3.8/include/
cp -r Python-3.8.19/Include/* python3.8/include/
git clone GitHub - pybind/pybind11: Seamless operability between C++11 and Python
git clone -b release/8.5 GitHub - NVIDIA/TensorRT: NVIDIA® TensorRT™ is an SDK for high-performance deep learning inference on NVIDIA GPUs. This repository contains the open source components of TensorRT.
cd TensorRT
git submodule update --init --recursive
cd python/
TRT_OSSPATH=${PWD}/… EXT_PATH=${PWD}/…/… ./build.sh

pip install build/dist/tensorrt-8.5.2.2-cp38-none-linux_aarch64.whl

The build.sh script is as follows:

Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.

Licensed under the Apache License, Version 2.0 (the “License”);

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

Apache License, Version 2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an “AS IS” BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

PYTHON_MAJOR_VERSION=${PYTHON_MAJOR_VERSION:-3}
PYTHON_MINOR_VERSION=${PYTHON_MINOR_VERSION:-8}
TARGET=${TARGET_ARCHITECTURE:-aarch64}
CUDA_ROOT=${CUDA_ROOT:-/usr/local/cuda}
ROOT_PATH=${TRT_OSSPATH}
EXT_PATH=${EXT_PATH}
WHEEL_OUTPUT_DIR=${ROOT_PATH}/python/build
HEADER_PATH=/usr/include/aarch64-linux-gnu

mkdir -p ${WHEEL_OUTPUT_DIR}
pushd ${WHEEL_OUTPUT_DIR}

Generate tensorrt.so

cmake … -DCMAKE_BUILD_TYPE=Release
-DTARGET=${TARGET}
-DPYTHON_MAJOR_VERSION=${PYTHON_MAJOR_VERSION}
-DPYTHON_MINOR_VERSION=${PYTHON_MINOR_VERSION}
-DEXT_PATH=${EXT_PATH}
-DCUDA_INCLUDE_DIRS=${CUDA_ROOT}/include
-DTENSORRT_ROOT=${ROOT_PATH}
-DTENSORRT_BUILD=${ROOT_PATH}/build/
make -j12

Generate wheel

TRT_MAJOR=$(awk ‘/^#define NV_TENSORRT_MAJOR/ {print $3}’ ${HEADER_PATH}/NvInferVersion.h)
TRT_MINOR=$(awk ‘/^#define NV_TENSORRT_MINOR/ {print $3}’ ${HEADER_PATH}/NvInferVersion.h)
TRT_PATCH=$(awk ‘/^#define NV_TENSORRT_PATCH/ {print $3}’ ${HEADER_PATH}/NvInferVersion.h)
TRT_BUILD=$(awk ‘/^#define NV_TENSORRT_BUILD/ {print $3}’ ${HEADER_PATH}/NvInferVersion.h)
TRT_VERSION=${TRT_MAJOR}.${TRT_MINOR}.${TRT_PATCH}.${TRT_BUILD}
TRT_MAJMINPATCH=${TRT_MAJOR}.${TRT_MINOR}.${TRT_PATCH}

echo “Generating python ${PYTHON_MAJOR_VERSION}.${PYTHON_MINOR_VERSION} bindings for TensorRT ${TRT_VERSION}”

expand_vars_cp () {
test -f ${1} || (echo “ERROR: File: ${1} does not exist!” && exit 1);
sed -e “s|##TENSORRT_VERSION##|${TRT_VERSION}|g”
-e “s|##TENSORRT_MAJMINPATCH##|${TRT_MAJMINPATCH}|g”
${1} > ${2}
}

pushd ${ROOT_PATH}/python/packaging
for dir in $(find . -type d); do mkdir -p ${WHEEL_OUTPUT_DIR}/$dir; done
for file in $(find . -type f); do expand_vars_cp $file ${WHEEL_OUTPUT_DIR}/${file}; done
popd
python3 setup.py -q bdist_wheel --python-tag=cp${PYTHON_MAJOR_VERSION}${PYTHON_MINOR_VERSION} --plat-name=linux_${TARGET}

popd

Thank you for your help!

Hi @2646490495 are you still experiencing issues? If so, please can you start a new topic specific to your issue so we can route it to the right people to help out! Thanks so much.

Sophie