llama_index: [Question]: import error

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

I updated today’s version to 0.10.1, and found a baffling error.

May I know what the problem is?

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

error msg: ImportError: cannot import name ‘VectorStoreIndex’ from ‘llama_index.core’ (unknown location)

About this issue

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

Most upvoted comments

You can try this once too:

pip3 uninstall llama-index pip3 install llama-index --upgrade --no-cache-dir --force-reinstall

🤖

The error message “ImportError: cannot import name ‘VectorStoreIndex’ from ‘llama_index.core’” suggests that the module ‘llama_index.core’ does not contain a definition for ‘VectorStoreIndex’.

However, from the provided context, it is clear that ‘VectorStoreIndex’ is defined in the ‘llama_index.indices.vector_store.base’ module, not in ‘llama_index.core’.

Therefore, you should import ‘VectorStoreIndex’ from ‘llama_index.indices.vector_store.base’ instead of ‘llama_index.core’. Here is the correct import statement:

from llama_index.indices.vector_store.base import VectorStoreIndex

This should resolve the ImportError you’re facing. Additionally, ensure there is no file or folder named llama_index in your current working directory and consider using a virtual environment.

This solution was also suggested in a similar issue: [Question]: cannot import name ‘VectorStoreIndex’ from ‘llama_index’

If you are still facing issues after making this change, it could be due to a problem with your installation or a version mismatch. In that case, you might want to consider reinstalling the LlamaIndex package.

As for the changes made in the LlamaIndex codebase from version v0.10.0 to v0.10.1 that could have caused the ImportError, I wasn’t able to find an answer within the repository. It’s possible that the answer may be available elsewhere or I could have missed it.

If you need further assistance, please provide more details about your environment and the steps you took before encountering the error.

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.

You can try this once too:

pip3 uninstall llama-index pip3 install llama-index --upgrade --no-cache-dir --force-reinstall

Can confirm that this suggestion worked for me as well, thank you.

Hi there,

Perhaps it is easier to work at the new environment. For window system, I am able to import VectorStoreIndex and SimpleDirectoryReader

conda create -n llama python=3.11 anaconda
conda activate llama
pip install llama-index

python
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
image

You can try this once too:

pip3 uninstall llama-index pip3 install llama-index --upgrade --no-cache-dir --force-reinstall

This worked for me.

@logan-markewich Thank you very much, I followed your instructions and I did not use the conda to create the new venv and it worked! Also, yes, I had it globally too, so probably the unistallation in the beginning helped too.

With the the new venv activate can you please run pip freeze | grep llama-index and share the output here?

Can you also try the import statement when using python interpreter with venv activated. Specifically:

source venv/bin/activate
python

# in the python interpreter
>>> from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

And share the output. If running a script, please ensure you are indeed running the script using the correct venv.

@kouskouss do you have llama-index installed globally in thr base env?

Since there was a switch to namespaced packages, any remnants of an old install will cause some issue.

Maybe try with venv instead?

In a fresh terminal

pip uninstall llama-index  # just to be sure
python -m venv venv 
source venv/bin/activate
pip install llama-index --upgrade --no-cache-dir --force-reinstall

Thank you all for your response. As Calculus C said, I ran it with the following code and it was resolved! `conda create -n llama python=3.11 anaconda conda activate llama pip install llama-index

python from llama_index.core import VectorStoreIndex, SimpleDirectoryReader`