Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: partially initialized module 'openai' has no attribute 'Completion' #3

Closed
osilkin98 opened this issue Feb 5, 2021 · 7 comments

Comments

@osilkin98
Copy link

When importing openai and running the following code:

import openai
openai.api_key = "api key omitted 😉 "
openai.Completion.create(
  engine="davinci",
  prompt="Once upon a time",
  max_tokens=5
)

I get the the following error message:

Traceback (most recent call last):
  File "c:\Users\Oleg\Documents\Programming\OpenAI\random.py", line 1, in <module>
    import openai
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\__init__.py", line 30, in <module>
    from openai.api_resources import *  # noqa
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\api_resources\__init__.py", line 1, in <module>
    from openai.api_resources.branch import Branch
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\api_resources\branch.py", line 2, in <module>
    from openai.api_resources.abstract.engine_api_resource import EngineAPIResource
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\api_resources\abstract\__init__.py", line 5, in <module>
    from openai.api_resources.abstract.api_resource import APIResource
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\api_resources\abstract\api_resource.py", line 3, in <module>
    from openai import api_requestor, error, six, util
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\api_requestor.py", line 15, in <module>
    from openai import error, http_client, version, util, six
  File "C:\Users\Oleg\Documents\Programming\OpenAI\venv\lib\site-packages\openai\http_client.py", line 8, in <module>
    import random
  File "c:\Users\Oleg\Documents\Programming\OpenAI\random.py", line 13, in <module>
    response = openai.Completion.create(
AttributeError: partially initialized module 'openai' has no attribute 'Completion' (most likely due to a circular import)

I've tried re-installing it via pip install --upgrade openai but I still get the same error, however VSCode seems to know that Completion is a class within the openai module.

@rachellim
Copy link
Collaborator

rachellim commented Mar 18, 2021

In this case, it looks like the circular dependency is that the file you're running is named random.py, which clashes with the python module random. Try naming your file something else?

@osilkin98
Copy link
Author

osilkin98 commented Mar 19, 2021 via email

pull bot referenced this issue in mcx/openai-python Oct 10, 2021
@agarre
Copy link

agarre commented Mar 1, 2023

Thanks @rachellim!

@georgechalhoub
Copy link

georgechalhoub commented Apr 18, 2023

The issue for me was that I named my file openai.py, I had to rename it to something else. Also, I had to delete openai.pyc afterwards.

@GeorgeC6
Copy link

I named my file openai.py too, exactly the issue.
Thanks Rachel!

@Avinash1357
Copy link

i faced the same issue as described above and renaming the file to anything other than 'openai' resolved the issue. thank you @rachellim

@medulka
Copy link

medulka commented Oct 25, 2023

I made the same mistake... thank you for discussing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants