0

I want to use openai.embeddings_utils import get_embeddings So already install openai

Name: openai
Version: 0.26.5
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: support@openai.com
License: 
Location: /Users/lima/Desktop/Paprika/Openai/.venv/lib/python3.9/site-packages
Requires: aiohttp, requests, tqdm
Required-by: 

This is my openai But why not use openai.embeddings_utils??

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
lima
  • 89
  • 3
  • 8

4 Answers4

2

First run this command pip install openai[embeddings].

Then import the embeddings_utils package lik this: from openai.embeddings_utils import get_embedding

You can find details here: https://github.com/openai/openai-python

khushmeeet
  • 56
  • 3
2

There are two possible reasons why you get the No module named 'openai.embeddings_utils'; 'openai' is not a package error.


REASON 1: Your Python code isn't correct

Run pip install openai in the terminal, and then write the following in your Python script:

import openai
from openai.embeddings_utils import get_embedding

# The rest of your code

Note: For an example of how to use embeddings, see this answer.


REASON 2: You named the file openai.py

Don't name the file openai.py.

If you upgrade both the OpenAI Python package and Python but the error persists, then you probably named the file openai.py.


If you upgrade both the OpenAI Python package and Python and use the code I posted above, you should get no errors.

Rok Benko
  • 14,265
  • 2
  • 24
  • 49
2

If you are trying to run this on your jupyter cell:

!pip install openai

import openai
from openai.embeddings_utils import get_embedding

and you get this error:

ModuleNotFoundError                       Traceback (most recent call last)
C:\Users\NAVIGA~1\AppData\Local\Temp/ipykernel_36768/3211534756.py in <module>
      1 import openai
----> 2 from openai.embeddings_utils import get_embedding

~\AppData\Roaming\Python\Python39\site-packages\openai\embeddings_utils.py in <module>
      5 import plotly.express as px
      6 from scipy import spatial
----> 7 from sklearn.decomposition import PCA
      8 from sklearn.manifold import TSNE
      9 from sklearn.metrics import average_precision_score, precision_recall_curve

ModuleNotFoundError: No module named 'sklearn'

then you have to :

!pip install scikit-learn

Now try:

import openai
from openai.embeddings_utils import get_embedding

It will run successfully

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
1

I had the same problem. I don't know why pip wasn't installing some files. I solved by manually downloading embeddings_utils.py inside my virtual env .\venv\Lib\site-packages\openai\ folder. You might need to do the same for datalib.py

Note: if the folder is missing, openai may not be installed in the venv. To be sure you are actually installing on the virtual env, activate it and then use the command: .\venv\Scripts\python.exe -m pip install openai