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

AttributeError: module 'openai' has no attribute 'ChatCompletion'

Open emilycowe opened this issue 2 years ago • 1 comments

Describe the bug

Hello.

I cant access gpt-3.5-turbo with python because I seem to be getting the error " AttributeError: module ‘openai’ has no attribute ‘ChatCompletion’"

I have updated to openai v0.27.0, as well as tried using new API keys just incase that was causing the issue. Ive double checked that I actually have updated to the new version of openai 0.27.0 by running “pip list”. Ive also tried " pip install --upgrade openai " and “pip install openai-0.27.0-py3-none-any.whl”

Im not sure what else I can try, does anyone have any ideas? Thanks.

To Reproduce

import os import openai openai.api_key = os.getenv("key")

completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": "Hello!"} ] )

print(completion.choices[0].message)

Code snippets

No response

OS

macOS

Python version

Python v3.11.2

Library version

openai 0.27.0

emilycowe avatar Mar 02 '23 13:03 emilycowe

this issue is occurring for version v0.26.5, Upgrade to v0.27.0

Tried Screenshot 2023-03-02 at 11 28 38 PM

Working on v0.27.0 Screenshot 2023-03-02 at 11 29 15 PM

navyad avatar Mar 02 '23 17:03 navyad

I am using v0.27.0, here is a screenshot of the output for "pip show openai" Screenshot 2023-03-02 at 3 09 51 pm

emilycowe avatar Mar 02 '23 18:03 emilycowe

I can confirm, I'm having the same issue. I'm using poetry for dependency management and it says I have v0.27.0 installed but still getting the AttributeError.

xEricL avatar Mar 02 '23 19:03 xEricL

I just fixed the issue by creating a new virtual environment and reinstalling all my dependencies inside the new environment.

In your case, @emilycowe, I suggest going to your site-packages directory and deleting the openai folder(s), and then running the pip install command again.

xEricL avatar Mar 02 '23 19:03 xEricL

Yeah, sorry about this folks, it is a dependency management issue which Python makes harder than it has to be. If you create a new virtual env, you should be fine. I am closing this for now but the guidance is to make a new virtual env.

logankilpatrick avatar Mar 03 '23 14:03 logankilpatrick

yea a simple. "pip uninstall openai"....then "pip install openai" inside the virtual environment fixed my issue. Easy day!

Juniorduc44 avatar Apr 11 '23 00:04 Juniorduc44