llama_index: [Bug]: import error generated by SimpleDirectoryReader()

Bug Description

After upgrading to 0.10.4 SimpleDirectoryReader() generates an import error as it cannot find “DocxReader” in “llama_index.readers.file”.

image

Version

0.10.3

Steps to Reproduce

import openai import os import llama_index.core.readers as readers

openai.api_key = os.environ[‘OPENAI_API_KEY’]

source_dir_html = ‘/home/wb200/data/llm/doc/MLX_AU/test/html/’

reader = readers.SimpleDirectoryReader(input_dir=source_dir_html) documents = reader.load_data()

Relevant Logs/Tracbacks

Traceback (most recent call last):
  File "/home/wb200/anaconda3/envs/llm/lib/python3.11/site-packages/llama_index/core/readers/file/base.py", line 21, in _try_loading_included_file_formats
    from llama_index.readers.file import (
ImportError: cannot import name 'DocxReader' from 'llama_index.readers.file' (unknown location)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wb200/python/LLM/test.py", line 13, in <module>
    documents = reader.load_data()
                ^^^^^^^^^^^^^^^^^^
  File "/home/wb200/anaconda3/envs/llm/lib/python3.11/site-packages/llama_index/core/readers/file/base.py", line 396, in load_data
    SimpleDirectoryReader.load_file(
  File "/home/wb200/anaconda3/envs/llm/lib/python3.11/site-packages/llama_index/core/readers/file/base.py", line 303, in load_file
    default_file_reader_cls = SimpleDirectoryReader.supported_suffix_fn()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/wb200/anaconda3/envs/llm/lib/python3.11/site-packages/llama_index/core/readers/file/base.py", line 35, in _try_loading_included_file_formats
    raise ImportError("`llama-index-readers-file` package not found")
ImportError: `llama-index-readers-file` package not found

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 1
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@datascientist

pip install -U llama-index-readers-file

I’m surprised you had this issue, unless you only installed core

@jiyzhang please create a fresh venv and try again

I created a new env with conda and didn’t encounter this issue again. thanks

🤖

Based on the error message you provided, it seems like the DocxReader class cannot be found in the llama_index.readers.file module. This could be due to a change in the import structure in the LlamaIndex v0.10.4 update.

The DocxReader class might have been moved to a different module or renamed. You suggested that the import should be written as “from llama_index.readers.file.docs import DocxReader”. This could be correct if the DocxReader class was moved to the docs module in the llama_index.readers.file package.

To confirm this, you can check the source code of the llama_index.readers.file package in the LlamaIndex repository. If the DocxReader class is indeed in the docs module, you should update your import statement accordingly.

However, if you can’t find the DocxReader class in the docs module or anywhere else in the llama_index.readers.file package, it’s possible that the class was removed or renamed in the v0.10.4 update. In this case, you should check the release notes or the migration guide for v0.10.4 to see if there are any notes about changes to the DocxReader class.

If you’re still having trouble, please provide more information about your environment (e.g., Python version, operating system) and any other relevant details about your setup. This will help me better understand the issue and provide a more accurate solution.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

I have already downloaded the llama-index-readers-file, same issue 😃

On Wed, 21 Feb 2024 at 15:58, Manjunath Janardhan @.***> wrote:

@datascientist https://github.com/datascientist

pip install -U llama-index-readers-file

I’m surprised you had this issue, unless you only installed core

Thanks! This worked for me as well!

— Reply to this email directly, view it on GitHub https://github.com/run-llama/llama_index/issues/10773#issuecomment-1956839683, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGGLRBJHYPTA5BVYYDEK6JLYUYDQDAVCNFSM6AAAAABDLP4T5GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJWHAZTSNRYGM . You are receiving this because you commented.Message ID: @.***>

@jiyzhang please create a fresh venv and try again

I created a new env with conda and didn’t encounter this issue again. thanks

Same here

@wb200 can you try with a fresh venv?

For example, I do

python -m venv venv
source venv/bin/activate
pip install llama-index

And then it works for me

Haven’t tried that yet as I’m used to conda env system. And it doesn’t seem to work there.