导入错误:无法从“llama_index”(未知位置)导入名称“VectorStoreIndex”

问题描述 投票:0回答:1

当我尝试导入以下库时遇到了这个问题,它给出了错误“ImportError:无法从‘llama_index’(未知位置)导入名称‘VectorStoreIndex’”

我早上运行了完全相同的代码,它运行得很好。

我做到了

!pip install llama_index

from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
from llama_index.llms import HuggingFaceLLM
from llama_index.prompts.prompts import SimpleInputPrompt

我尝试注释掉第一行,但 HuggingFaceLLM 模块遇到了同样的问题 SimpleInputPrompt 也有同样的问题,出现错误“ModuleNotFoundError:没有名为 'llama_index.prompts' 的模块”

首先,我在 sagemaker 笔记本中遇到了问题,所以我认为问题出在 sagemaker 笔记本上,所以我启动了一个干净的新笔记本,但遇到了同样的错误。 因此,我在本地 Jypiter 笔记本、google collab 笔记本、sagemaker studiolab 笔记本中尝试了代码,但遇到了同样的错误。

python jupyter-notebook amazon-sagemaker huggingface llama-index
1个回答
0
投票

我认为这个错误是因为pip安装而发生的。
我遇到了同样的错误,我发现这个错误可以通过 pip 安装简单地修复。

您是否检查一下删除所有 llama-* 相关软件包并重新安装 llama-index 后是否会出现相同的错误?

pip chache purge

此命令将帮助 pip 不安装以前安装的缓存包。

© www.soinside.com 2019 - 2024. All rights reserved.