Install & Compatibility
Where this runs
tested against v11.0.0.114 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
build_error
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 64.3s · import 0.600s · 4505.6MB
4526MB installed
● package 4526MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
tensorrt
✓ import tensorrt as trt
Standard alias for brevity.
Logger
✓ from tensorrt import Logger
Accessing the main logger class.
cudart
✓ from cuda import cudart
For CUDA Runtime API calls, using the 'cuda-python' library.
Builder
✓ trt.Builder
Used to create and configure TensorRT engines.
NetworkDefinitionCreationFlag
✓ trt.NetworkDefinitionCreationFlag
Enum for network creation flags, e.g., EXPLICIT_BATCH.
This quickstart demonstrates how to build a simple TensorRT engine for an identity operation. It uses the `cuda-python` library for CUDA memory management, reflecting modern TensorRT usage. The process involves creating a logger, builder, network definition, configuration, defining input/output tensors, building the engine, and then performing a basic inference with device memory management.
import tensorrt as trt
import numpy as np
from cuda import cudart # Using cuda-python as per release notes
# 1. Create Logger
TRT_LOGGER = trt.Logger(trt.Logger.WARNING)
def build_engine():
# 2. Create Builder
builder = trt.Builder(TRT_LOGGER)
# 3. Create NetworkDefinition
# EXPLICIT_BATCH is required for dynamic shapes or when batch size is a dimension
network = builder.create_network(1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH))
# 4. Create BuilderConfig
config = builder.create_builder_config()
config.max_workspace_size = 1 << 20 # 1 MiB
# Define input tensor (e.g., a simple 1x3x16x16 input)
input_tensor = network.add_input(name="input_tensor", dtype=trt.float32, shape=(1, 3, 16, 16))
# Add an identity layer (input -> output directly)
output_tensor = network.add_identity(input_tensor).get_output(0)
# 6. Mark output
network.mark_output(output_tensor)
output_tensor.name = "output_tensor"
# Build and return the engine
engine = builder.build_engine(network, config)
if not engine:
raise RuntimeError("Failed to build TensorRT engine")
return engine
def main():
engine = None
runtime = None
context = None
device_input = None
device_output = None
try:
engine = build_engine()
print("TensorRT engine built successfully!")
# Create runtime and execution context
runtime = trt.Runtime(TRT_LOGGER)
# For demonstration, we use the already built engine. In real apps, you might deserialize.
context = engine.create_execution_context()
# Prepare input data
host_input = np.random.rand(1, 3, 16, 16).astype(np.float32)
host_output = np.empty_like(host_input) # Output shape is same as input for identity
# Allocate device memory
_, device_input = cudart.cudaMalloc(host_input.nbytes)
_, device_output = cudart.cudaMalloc(host_output.nbytes)
# Copy input to device
cudart.cudaMemcpy(device_input, host_input.ctypes.data, host_input.nbytes, cudart.cudaMemcpyKind.cudaMemcpyHostToDevice)
# Execute inference
# The execute_v2 takes an iterable of device pointers in the order of inputs and outputs
bindings = [int(device_input), int(device_output)]
context.execute_v2(bindings)
# Copy output back to host
cudart.cudaMemcpy(host_output.ctypes.data, device_output, host_output.nbytes, cudart.cudaMemcpyKind.cudaMemcpyDeviceToHost)
print(f"Input shape: {host_input.shape}")
print(f"Output shape: {host_output.shape}")
print(f"Input (first 5 elements): {host_input.flatten()[:5]}")
print(f"Output (first 5 elements): {host_output.flatten()[:5]}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Clean up resources
if device_input: cudart.cudaFree(device_input)
if device_output: cudart.cudaFree(device_output)
if context: del context
if engine: del engine
if runtime: del runtime
if __name__ == "__main__":
main()
Upgrade
Version history
11.0.0.114latest on PyPI · released May 27, 2026
Audit
Dependencies
nvidia-tensorrtrequiredCore TensorRT Python bindings, pulled by 'tensorrt' metapackage.
numpyrequiredRequired for array manipulation and data handling.
cuda-pythonrequiredRecommended for CUDA API interactions (e.g., memory management) instead of pycuda since TensorRT 10.14.