ModuleNotFoundError for openai.embeddings_utils
ModuleNotFoundError: 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.
Fix it fast
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__)"2Match what you see, then jump to its fix
- 1
The 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
The 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
- 1
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/null2Fix
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
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
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:
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- MenuloA restaurant discovery platform in Germany, kept current by a Python ingestion pipeline.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
AI
Old openai.ChatCompletion or openai.Embedding code breaks on a new SDK
APIRemovedInV1
The Python SDK was rewritten in version 1.0.
2 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fixAI
Azure OpenAI fails with an SSL certificate verification error
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]
The client checks the endpoint's certificate against its CA bundle, which is certifi by default.
2 causes, each with a fixAI
The OpenAI client says the API key is missing
Missing credentials. Please pass an `api_key`
OpenAI() looks for an api_key argument first and then the OPENAI_API_KEY environment variable.
3 causes, each with a fixAI
OpenAI says the model is a chat model and not supported in the v1/completions endpoint
This is a chat model and not supported in the v1/completions endpoint
The v1/completions endpoint accepts completion models such as gpt-3.5-turbo-instruct.
3 causes, each with a fixAI
TypeError when you index an OpenAI response like a dictionary
TypeError: 'ChatCompletion' object is not subscriptable
Since SDK 1.0 the OpenAI Python library returns Pydantic model objects instead of dictionaries, so response['choices'] fails.
2 causes, each with a fix