Unable to install TensorRT in Conda Env

Description

I am not able to install TensorRT in a miniconda env. It gets installed successfully as indicated in the “Steps To Reproduce”, but when I import it gives an error that “ModuleNotFoundError: No module named ‘tensorrt_bindings’”

Environment

tensorrt-installation-error-log.txt (19.1 KB)

TensorRT Version: 10.7.0
GPU Type: Tesla 4
Nvidia Driver Version:
CUDA Version: 12.1
CUDNN Version:
Operating System + Version: Ubuntu 20.04
Python Version (if applicable): 3.12
TensorFlow Version (if applicable):
PyTorch Version (if applicable): 2.5.1
Baremetal or Container (if container which image + tag):

Relevant Files

Please attach or include links to any models, data, files, or scripts necessary to reproduce your issue. (Github repo, Google Drive, Dropbox, etc.)

Steps To Reproduce

It takes following 8 steps to reproduce this issue.

  1. conda create --name asr python=3.12

  2. conda activate asr

  3. conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia

  4. python3 -m pip install onnx

  5. python3 -m pip install onnxruntime

  6. python3 -m pip install onnxruntime-gpu

  7. python3 -m pip install --upgrade tensorrt

  8. python
    Python 3.12.8 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 16:31:09) [GCC 11.2.0] on linux
    Type “help”, “copyright”, “credits” or “license” for more information.

import torch
import onnx
import tensorrt
Traceback (most recent call last):
File “”, line 1, in
File “/home/puneet/.conda/envs/asr/lib/python3.12/site-packages/tensorrt/init.py”, line 18, in
from tensorrt_bindings import *
ModuleNotFoundError: No module named ‘tensorrt_bindings’

The error “ModuleNotFoundError: No module named ‘tensorrt_bindings’” when trying to import TensorRT in a Miniconda environment may be caused by several factors. Here are some possible causes and solutions:

Possible Causes:

  1. Incorrect Installation: TensorRT may not have been installed correctly, leading to missing modules.
  2. Missing Dependencies: Essential dependencies required for TensorRT might not be installed or properly configured in your Miniconda environment.
  3. Path Configuration Issues: The path to the TensorRT installation might not be added to the system or Python path, preventing Python from locating the module.
  4. Version Compatibility: The installed version of TensorRT may not be compatible with the version of Python or other packages in your Miniconda environment.

Possible Solutions:

  1. Reinstall TensorRT: Try reinstalling TensorRT in the Miniconda environment. Use the command:

    conda install -c nvidia tensorrt
    

    Ensure that you use a compatible version as specified in the documentation.

  2. Check Dependencies: Confirm that all required dependencies for TensorRT are installed in your environment. Refer to the TensorRT documentation for a full list of dependencies.

  3. Update PATH and Python Path: Ensure that the path to the TensorRT installation is included in your system’s PATH and the Python path. You can append the TensorRT installation path to the PATH variable using:

    export PATH=$PATH:/path/to/tensorrt
    

    Also, ensure that the TensorRT Python bindings are accessible in your Python environment.

  4. Verify Version Compatibility: Make sure the version of TensorRT you are trying to install is compatible with your Python version (3.12 in this case) and other libraries. Check the compatibility matrix in the official TensorRT documentation.

By following these troubleshooting steps and verifying your setup, you should be able to resolve the ‘ModuleNotFoundError’ and successfully import TensorRT in your Miniconda environment.

Your suggestion to use “conda install -c nvidia tensorrt” does not work. Here is the terminal output of this command:

==================================
$ conda install -c nvidia tensorrt
Channels:

  • nvidia
  • defaults
  • pytorch
    Platform: linux-64
    Collecting package metadata (repodata.json): done
    Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  • tensorrt

Current channels:

To search for alternate channels that may provide the conda package you’re
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

1 Like

Hi I met the same issue as you did, Have you found a solution for this?