Find answers from the community

Updated 10 months ago

Hi all, I have this odd piece of

Hi all, I have this odd piece of behaviour that just doesn't make sense to me where I get an ImportError when attempting to use a SimpleDirectoryReader
O
W
28 comments
faulty code
Plain Text
parser = LlamaParse(
    api_key=[redacted],
    result_type="markdown" 
)


file_extractor = {".pdf": parser}
reader = SimpleDirectoryReader("./data", file_extractor=file_extractor)
documents = reader.load_data()
Plain Text
ImportError            Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\llama_index\core\readers\file\base.py:22, in _try_loading_included_file_formats()
     21 try:
---> 22     from llama_index.readers.file import (
     23         DocxReader,
     24         EpubReader,
     25         HWPReader,
     26         ImageReader,
     27         IPYNBReader,
     28         MarkdownReader,
     29         MboxReader,
     30         PandasCSVReader,
     31         PDFReader,
     32         PptxReader,
     33         VideoAudioReader,
     34     )  # pants: no-infer-dep
     35 except ImportError:

ImportError: cannot import name 'DocxReader' from 'llama_index.readers.file' (unknown location)
In the llama_index/CORE/readers/file it is trying to import form llama_index.readers.file, whilst I'm 99% sure that llama_index.readers doesn't even exist anymore, as it is now llama_index.core.readers
Even when looking at the codebase on github, the readers/file import is clearly nested in the core namespace.
Pretty sure I'm missing some minor stupid detail here πŸ˜…
You'll have to install this to use readers: pip install llama-index-readers-file
With v0.10.x all the loaders/agents/tools got converted into pypi package
Requirement already statisfied πŸ€”
Pretty sure this is up to date
Attachment
image.png
This is with the latest version?
Plain Text
Name: llama-index
Version: 0.10.13.post1
Summary: Interface between LLMs and your data
Home-page: https://llamaindex.ai
Author: Jerry Liu
Author-email: jerry@llamaindex.ai
License: MIT
Location: C:\Users\Niek\AppData\Local\Programs\Python\Python311\Lib\site-packages
Requires: llama-index-agent-openai, llama-index-cli, llama-index-core, llama-index-embeddings-openai, llama-index-indices-managed-llama-cloud, llama-index-legacy, llama-index-llms-openai, llama-index-multi-modal-llms-openai, llama-index-program-openai, llama-index-question-gen-openai, llama-index-readers-file, llama-index-readers-llama-parse
Required-by: 
Pretty sure this is the latest
Yeah its latest, let me try
Let me run this in a .py file real quick to see if my python versions aren't just acting up
Just running the imports in a .py script gives me errors? πŸ˜…
Plain Text
from llama_index.core.readers import SimpleDirectoryReader
from llama_index.core.storage.docstore import SimpleDocumentStore
from llama_index.core.node_parser import SimpleNodeParser
from llama_parse import LlamaParse 
import os
import nest_asyncio

Plain Text
ImportError: cannot import name 'StorageContext' from partially initialized module 'llama_index.core.storage.sto StorageContextrage_context' (most likely due to a circular import)
First case worked for me on colab
Attachment
image.png
you're import simpledirectoryreader from llamaindex.core and not llamaindex.core.readers?
also second worked for me:
Attachment
image.png
Let me purge llamaindex and reinstall everything
also importing from reader worked too
Yet another timeless classic, it seems that there was a rogue python version in my environment variables that was actively boycotting my imports
πŸ€¦β€β™‚οΈ
Thanks for your help regardless!
Add a reply
Sign up and join the conversation on Discord