Why do I get this error, "ModuleNotFoundError: No module named 'onnxruntime_genai'" from running the code below even though I ran these first: "! pip install onnxruntime==1.21.0 -U", "! pip install onnxruntime-genai"?

Ufedo Omale 45 Reputation points
2025-08-08T12:35:07.4333333+00:00

Question: Why do I get this error, "ModuleNotFoundError: No module named 'onnxruntime_genai'" from running the code below even though I ran these first: "! pip install onnxruntime==1.21.0 -U", "! pip install onnxruntime-genai"?

Code:

import onnxruntime_genai as og
import numpy as np
import os
Azure Machine Learning
{count} votes

1 answer

Sort by: Most helpful
  1. Aryan Parashar 150 Reputation points Microsoft External Staff Moderator
    2025-08-11T06:32:54.2766667+00:00

    Sometimes, even after installing a module with pip install in a python environment, a ModuleNotFoundError can occur.

    This is typically due to one of two reasons:

    1. The environment is not correctly activated.
    2. The global installation or virtual environment is corrupted, or there are conflicting dependencies.

    Follow the steps below to solve the issue:

    • Conda:
        conda create --name new_env python=3.11
        conda activate new_env 
        pip install onnxruntime-genai
      
    • venv (for VS Code):
        python -m venv env1 
        
        # On macOS/Linux: 
        source env1/bin/activate 
        
        # On Windows: 
        env1\Scripts\activate 
        
        
        pip install onnxruntime-genai
      
      Let me know if you are still facing the issue. Feel free to accept this as an answer
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.