Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

ModuleNotFoundError for openai.embeddings_utils

ErrorModuleNotFoundError: No module named 'openai.embeddings_utils'

Short answer

Two different things produce this error. The helper module openai.embeddings_utils was removed in SDK 1.0, so any version from 1.0 onward lacks it. Separately, a file of yours named openai.py in the script folder shadows the real package, which gives the 'is not a package' wording. Remove the import or rename the file.

  • Applies to openai Python SDK 1.x and later, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask Python where it loads openai from. A path inside your project means your own file is hiding the package; a site-packages path means the module was simply removed.

    python -c "import openai; print(openai.__file__); print(openai.__version__)"
  2. 2Match what you see, then jump to its fix

    1. 1The message ends with 'openai' is not a package, and the printed path points into your project.A file or folder named openai shadows the real packageFix
    2. 2The path points into site-packages, the version is 1.0.0 or higher, and the code does 'from openai.embeddings_utils import ...'.The helper module was removed in SDK 1.0Fix

What does the error look like?

  • ModuleNotFoundError: No module named 'openai.embeddings_utils'
  • 'openai' is not a package

Cause 1 of 2

A file or folder named openai shadows the real package

1Check

Python puts the folder of the running script at the front of its search path, so a local openai.py is found before the installed package.

ls openai.py openai/ __pycache__/openai* 2>/dev/null

2Fix

Rename the file (and delete its __pycache__ entry), then run the script again.

mv openai.py openai_demo.py
rm -rf __pycache__

3Verify

The path printed now points into site-packages.

python -c "import openai; print(openai.__file__)"

Confirmed by docs.python.org

Did this fix it?

Cause 2 of 2

The helper module was removed in SDK 1.0

1Check

The migration guide states that openai.embeddings_utils was removed and now lives in the cookbook.

grep -rn "embeddings_utils" --include='*.py' .

2Fix

Stop importing it. Call the SDK directly with client.embeddings.create and copy the small helper you need (such as a cosine similarity function) into your own code.

from openai import OpenAI

client = OpenAI()
resp = client.embeddings.create(model=EMBEDDING_MODEL, input=["first text"])

3Verify

The call returns a response object and the import error is gone.

print(type(resp))

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Never name your own file after a package you import (openai.py, requests.py, random.py).
  • Depend on the SDK's documented client methods, not on helper modules.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.