OpenAI import not working

Hi trying to use the very simpel example on the documentation site

from openai import OpenAI
client = OpenAI()

completion =
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}


But everytime i get the same error :ModuleNotFoundError: No module named ‘openai’.
my set up is a virtualenviroment that is active with a openai version 1.12.0 and python version 3.12.2. why oh why cant my python program find the package.

Assuming everything is correctly installed, you might look at your paths to ensure python can see where openai is installed.

1 Like

Please ensure that your Python virtual environment is activated, and try the command:
pip show openai

If the OpenAI module is installed correctly, you will see a display like this:

Name: openai
Version: 1.12.0
Summary: The official Python library for the openai API
Author-email: OpenAI
Location: {your path location goes here}
Requires: anyio, distro, httpx, pydantic, sniffio, tqdm, typing-extensions

If you don’t see the display like above, please check whether the virtual environment is active or if the OpenAI module is installed within the virtual environment.

1 Like