You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在NVIDIA PyTorch 19.05-py3容器中导入tensorrt模块失败求助

Why can't I import the tensorrt Python module in the nvcr.io/nvidia/pytorch:19.05-py3 container (even though TensorRT C++ samples work)?

Great question! Let’s break this down clearly:

Root Cause

Your TensorRT C++ samples run perfectly because the core TensorRT runtime libraries (like libnvinfer5) are installed via the Debian package you set up. However, the Python tensorrt module is missing for two key reasons:

  • The nvcr.io/nvidia/pytorch:19.05-py3 image doesn’t come with TensorRT’s Python bindings pre-installed by default.
  • The Debian TensorRT packages you installed only include C++ libraries, headers, and samples—they don’t automatically configure the Python module to be visible to your Python interpreter.

Fixes to Try

Since your TensorRT version is 5.1.5.0 (matched with CUDA 10.1), grab the compatible wheel package and install it:

  1. Download the correct wheel for Python 3.6 (the version included in this container):
    wget https://developer.download.nvidia.com/compute/machine-learning/tensorrt/secure/5.1.5.0/ubuntu1804/x86_64/TensorRT-5.1.5.0-cp36-none-linux_x86_64.whl
    
  2. Install it with pip:
    pip install TensorRT-5.1.5.0-cp36-none-linux_x86_64.whl
    
  3. Verify the installation works:
    python3 -c "import tensorrt; print(f'TensorRT version: {tensorrt.__version__}')"
    
    You’ll see TensorRT version: 5.1.5.0 if the setup was successful.

Option 2: Manually Add TensorRT’s Python Path to PYTHONPATH

If you prefer not to install the wheel, you can explicitly tell Python where to find the TensorRT module:

  1. Locate the TensorRT Python module directory on your system:
    find /usr -name "tensorrt" -type d
    
    This will likely return a path like /usr/lib/python3.6/dist-packages/tensorrt.
  2. Add this path to your PYTHONPATH environment variable:
    export PYTHONPATH=/usr/lib/python3.6/dist-packages:$PYTHONPATH
    
    To make this permanent, add the line above to your ~/.bashrc file.
  3. Test the import again:
    python3 -c "import tensorrt"
    

Quick Clarification

The gap between working C++ samples and missing Python support is straightforward: C++ samples link directly against the pre-installed TensorRT shared libraries. Python, however, needs specific Python bindings (.so files and helper modules) to be present in its search path—something the Debian package doesn’t handle automatically for you.

内容的提问来源于stack exchange,提问作者Bilal Siddiqui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:14:56