How to beginner · 3 min read

How to install ONNX Runtime

Quick answer
Install ONNX Runtime in Python using pip install onnxruntime. This installs the core runtime for executing ONNX models efficiently on your system.

PREREQUISITES

  • Python 3.6+
  • pip

Setup

To install ONNX Runtime, ensure you have Python 3.6 or higher and pip installed on your system. Use the following command to install the CPU-only version of ONNX Runtime via pip.

bash
pip install onnxruntime

Step by step

After installation, verify the installation and run a simple inference example using ONNX Runtime.

python
import onnxruntime as ort
import numpy as np

# Verify ONNX Runtime version
print(f"ONNX Runtime version: {ort.__version__}")

# Create a simple ONNX model input (e.g., for a model expecting a float tensor)
input_data = np.array([[1.0, 2.0, 3.0]], dtype=np.float32)

# Normally, you would load an ONNX model file. For demonstration, we just show the API usage.
# Example: session = ort.InferenceSession("model.onnx")
# outputs = session.run(None, {"input": input_data})

print("ONNX Runtime installed and ready for inference.")
output
ONNX Runtime version: 1.15.1
ONNX Runtime installed and ready for inference.

Common variations

For GPU support, install the CUDA-enabled package with:

pip install onnxruntime-gpu

Use onnxruntime-gpu if you have a compatible NVIDIA GPU and CUDA installed. For asynchronous inference, use ONNX Runtime's async APIs available in the Python package.

python
import onnxruntime as ort
import asyncio

async def async_inference():
    session = ort.InferenceSession("model.onnx")
    input_data = ...  # prepare input
    outputs = await session.run_async(None, {"input": input_data})
    print(outputs)

# asyncio.run(async_inference())  # Uncomment to run async inference

Troubleshooting

  • If you get ModuleNotFoundError, ensure onnxruntime is installed in your active Python environment.
  • For GPU installation errors, verify CUDA and cuDNN versions are compatible with your onnxruntime-gpu version.
  • Use pip show onnxruntime to check the installed version.

Key Takeaways

  • Use pip install onnxruntime for CPU-only ONNX Runtime installation.
  • Install onnxruntime-gpu for GPU acceleration with compatible CUDA setup.
  • Verify installation by importing onnxruntime and checking its version.
  • Troubleshoot by confirming Python environment and CUDA compatibility for GPU.
  • ONNX Runtime enables efficient execution of ONNX models across platforms.
Verified 2026-04
Verify ↗