openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

cannot import name 'OpenAI' from 'openai' v1.2.0

Open StrumykTomira opened this issue 3 years ago • 2 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [X] This is an issue with the Python library

Describe the bug

ImportError: cannot import name 'OpenAI' from 'openai'

The not working code was taken from the official documentation.

To Reproduce

from openai import OpenAI

Code snippets

# There are many following errors
from pathlib import Path

from openai import OpenAI
# ImportError: cannot import name 'OpenAI' from 'openai'

client = OpenAI()
# NameError: name 'OpenAI' is not defined

speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
# AttributeError: module 'client' has no attribute 'audio'
# response = client.Audio.speech.create(
# AttributeError: type object 'Audio' has no attribute 'speech'
  model="tts-1",
  voice="alloy",
  input="Today is a wonderful day to build something people love!"
)

response.stream_to_file(speech_file_path)

OS

Windows 10

Python version

Python v3.10.7

Library version

openai v1.2.0

StrumykTomira avatar Nov 09 '23 17:11 StrumykTomira

@StrumykTomira This will be an issue with your environment, how are you installing the package and running your code?

This snippet can be helpful:

import openai
print(openai.VERSION)

Everything should work once the above snippet outputs 1.1 or higher.

RobertCraigie avatar Nov 09 '23 19:11 RobertCraigie

pip install --upgrade openai pydub

KalvinThien avatar Jan 18 '24 13:01 KalvinThien