5

I'm getting error while running a python script on macOS

from openai.openai_object import OpenAIObject

ModuleNotFoundError: No module named 'openai.openai_object'

How do I fix it?

(llama-py3.12) bash-3.2$ python3 starter.py 
Traceback (most recent call last):
  File "/Users/imac/ROOT/Python/chatgpt/llama/starter.py", line 1, in <module>
    from llama_index import VectorStoreIndex, SimpleDirectoryReader
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/__init__.py", line 17, in <module>
    from llama_index.embeddings.langchain import LangchainEmbedding
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/embeddings/__init__.py", line 16, in <module>
    from llama_index.embeddings.openai import OpenAIEmbedding
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/embeddings/openai.py", line 18, in <module>
    from llama_index.llms.openai_utils import (
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/llms/__init__.py", line 23, in <module>
    from llama_index.llms.litellm import LiteLLM
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/llms/litellm.py", line 28, in <module>
    from llama_index.llms.litellm_utils import (
  File "/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages/llama_index/llms/litellm_utils.py", line 4, in <module>
    from openai.openai_object import OpenAIObject
ModuleNotFoundError: No module named 'openai.openai_object'

(llama-py3.12) bash-3.2$ which python
/Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/bin/python

(llama-py3.12) bash-3.2$ pip show openai
Name: openai
Version: 1.3.7
Summary: The official Python library for the openai API
Home-page: 
Author: 
Author-email: OpenAI <[email protected]>
License: 
Location: /Users/imac/Library/Caches/pypoetry/virtualenvs/llama-HG1XU64H-py3.12/lib/python3.12/site-packages
Requires: anyio, distro, httpx, pydantic, sniffio, tqdm, typing-extensions
Required-by: llama-index
(llama-py3.12) bash-3.2$ 
6
  • Maybe this one answers your question: No module named openai Commented Dec 1, 2023 at 20:09
  • 1
    My guess is that this is because of Python 3.12. It's a very recent python version and all data science libraries do not support it well yet. You should try with python 3.11. Commented Dec 1, 2023 at 20:19
  • 1
    @Eskapp I started with 3.7, didn't work then tried with 3.12. I'll try with 3.11. Commented Dec 1, 2023 at 21:20
  • 1
    3.7 is too old, there was not so so much genai back then ;) I would try 3.10 (works on my machine and the Mac of coworkers) and 3.11 Actually it seems that this is the same issue here, resolved by moving to Python 3.10: community.openai.com/t/… Commented Dec 1, 2023 at 21:25
  • 1
    @Eskapp Thanks man it worked with 3.10. Wasted my whole day figuring it out. Commented Dec 1, 2023 at 21:52

1 Answer 1

-1

According to the discussion in the comments back in Dec 2023, the trick is to use Python 3.10.

To future SO users, while that may had worked for OP back in Dec 2023, this may have changed over time as the different libraries start to support newer version of Python.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.