Raymond
Raymond

Reputation: 1258

ModuleNotFoundError: No module named 'openai.openai_object'

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$ 

Upvotes: 5

Views: 2797

Answers (1)

LHY
LHY

Reputation: 695

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.

Upvotes: -1

Related Questions