Find answers from the community

Updated 3 months ago

Import error

I just updated LlamaIndex and got this error: ImportError: cannot import name 'PromptTemplate' from 'llama_index.prompts' (/Users/jana/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/prompts/init.py) upon calling this query_engine = index.as_query_engine() on a vector index. Anyone experiencing the same issue and know how to resolve it?
L
J
7 comments
Hmm, maybe try uninstalling and reinstalling llama-index?

Do you have the full traceback?

The source code looks fine to me. It also works for me locally πŸ‘€ https://github.com/jerryjliu/llama_index/blob/main/llama_index/prompts/__init__.py
I have reinstalled the llama-index. Error occurs when I run from llama_index.prompts import PromptTemplate trace is simple: ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[18], line 1
----> 1 from llama_index.prompts import PromptTemplate

ImportError: cannot import name 'PromptTemplate' from 'llama_index.prompts' (/Users/jana/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/prompts/init.py)
If I run : query_engine = index.as_query_engine() then the trace is ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[19], line 1
----> 1 query_engine = index.as_query_engine()

File ~/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/indices/base.py:335, in BaseIndex.as_query_engine(self, kwargs) 333 def as_query_engine(self, kwargs: Any) -> BaseQueryEngine:
334 # NOTE: lazy import
--> 335 from llama_index.query_engine.retriever_query_engine import RetrieverQueryEngine
337 retriever = self.as_retriever(**kwargs)
339 kwargs["retriever"] = retriever

File ~/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/query_engine/init.py:1
----> 1 from llama_index.query_engine.citation_query_engine import CitationQueryEngine
2 from llama_index.query_engine.flare.base import FLAREInstructQueryEngine
3 from llama_index.query_engine.graph_query_engine import ComposableGraphQueryEngine

File ~/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/query_engine/citation_query_engine.py:10
8 from llama_index.indices.query.base import BaseQueryEngine
9 from llama_index.indices.query.schema import QueryBundle
---> 10 from llama_index.prompts import PromptTemplate
11 from llama_index.prompts.base import BasePromptTemplate
12 from llama_index.response.schema import RESPONSE_TYPE

ImportError: cannot import name 'PromptTemplate' from 'llama_index.prompts' (/Users/jana/work/LlamaIndexLangChain/jupyter/myenv/lib/python3.9/site-packages/llama_index/prompts/init.py)
is there anything else I could do ?
I downgraded and upgraded and somehow it started working... one of those strange things
So, it's ok, thank you!
Nice! Must have been a cached file or something πŸ˜…
Add a reply
Sign up and join the conversation on Discord