Cannot import OpenAI- python

from pathlib import Path
from openai import OpenAI

client = OpenAI(apikey='■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■IyBjnByu')
speech_file_path = Path(__file__).parent / "speech.mp3"
response =
    input="Your text goes here!"
ImportError                               Traceback (most recent call last)
Cell In[16], line 2
      1 from pathlib import Path
----> 2 from openai import OpenAI
      4 client = OpenAI(apikey='■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■IyBjnByu')
      5 speech_file_path = Path(__file__).parent / "speech.mp3"

ImportError: cannot import name 'OpenAI' from 'openai' (C:\Users\XXXXXX\AppData\Local\anaconda3\Lib\site-packages\openai\

Also i have already done !pip install --upgrade openai

Try this to double check you actualy updated in the right environment:

from openai import OpenAI, __version__

You likely have multiple installations of python going on, perhaps a user installation “anaconda3” and a system install.

You’ll need to do a “conda install -c conda-forge openai” as user to get that version upgraded.

1 Like

I’m on spyder openai but I get that error that I haven’t installed the openai library "ModuleNotFoundError: No module named ‘openai’