import llama_cpp ERROR
After successfully installing llama cpp Python using Python 3.10
Execute import llama_ cpp
Tips: Traceback (most recent call last): File "/root/anaconda3/lib/python3.10/site-packages/langchain/llms/llamacpp.py", line 106, in validate_environment from llama_cpp import Llama ImportError: cannot import name 'Llama' from partially initialized module 'llama_cpp' (most likely due to a circular import) (/mnt/www2/llama/llama_cpp.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "
Same here when trying to test caching.
@823863429 @gjmulder trying to repro, are you both using this from langchain?
@abetlen sorry - above is a different error to what I'm getting, as reported in #90
@823863429 @gjmulder尝试重现,你们都在使用 langchain 的这个吗?
Yes,try to use llama-cpp-python with langchain like: from langchain.llms import LlamaCpp from langchain import PromptTemplate, LLMChain template = """Question: {question}
Answer: Let's think step by step."""
prompt = PromptTemplate(template=template, input_variables=["question"]) llm = LlamaCpp(model_path="./ggml-model-q4_0.bin") llm_chain = LLMChain(prompt=prompt, llm=llm) question = "xxxxxx" llm_chain.run(question)
Are you still having the same issue with langchain?
I'm getting this error while trying to run the code detailed here: https://python.langchain.com/en/latest/modules/models/llms/integrations/llamacpp.html
I've downloaded the model ggml-model-q4_0.bin from here https://huggingface.co/Pi3141/alpaca-native-7B-ggml/tree/397e872bf4c83f4c642317a5bf65ce84a105786e
Here is the full output I'm seeing:
Traceback (most recent call last):
File "C:\Projects\LangChainPythonTest\env\lib\site-packages\langchain\llms\llamacpp.py", line 122, in validate_environment
from llama_cpp import Llama
ImportError: cannot import name 'Llama' from partially initialized module 'llama_cpp' (most likely due to a circular import) (c:\Projects\LangChainPythonTest\david\llama_cpp.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Projects\LangChainPythonTest\env\lib\site-packages\langchain\llms\llamacpp.py", line 122, in validate_environment
from llama_cpp import Llama
File "c:\Projects\LangChainPythonTest\david\llama_cpp.py", line 20, in <module>
llm = LlamaCpp(
File "pydantic\main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic\main.py", line 1102, in pydantic.main.validate_model
File "C:\Projects\LangChainPythonTest\env\lib\site-packages\langchain\llms\llamacpp.py", line 141, in validate_environment
raise ModuleNotFoundError(
ModuleNotFoundError: Could not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-python
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Projects\LangChainPythonTest\david\llama_cpp.py", line 20, in <module>
llm = LlamaCpp(
File "pydantic\main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic\main.py", line 1102, in pydantic.main.validate_model
File "C:\Projects\LangChainPythonTest\env\lib\site-packages\langchain\llms\llamacpp.py", line 141, in validate_environment
raise ModuleNotFoundError(
ModuleNotFoundError: Could not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-python
@dconlisk are you sure you pip installed llama-cpp-python in your environment?
Yes @abetlen, here's the output when I run that in my virtual environment:
Today, I am facing the same issue as the one reported by @dconlisk.
I kind of solved it, though I don't think is the perfect solution. However, I just did the following:
the sys.path.insert(0, <envs\your-environment-name\lib\site-packages>).
Apparently, I don't know for which reason, while working in a virtual env, python was not searching for the llama-cpp-python in site-packages of that virtual env.
Can we close this bug as it looks like a Python path issue?
To anyone having this problem, make sure the folder or file name you're importing llama_cpp to is not named llama_cpp or llama_cpp.py.
if you are using mac, you probably have brew installed version of python. try use
brew uninstall --ignore-dependencies [email protected]
I am using windows with python locally installed, I also tried with docker containers. The only thing that worked for me was to upgrade the llama-cpp-python version from 1.77 to 1.78.
try change your python file name llama_cpp.py
`ImportError Traceback (most recent call last) 4 frames /usr/local/lib/python3.10/dist-packages/langchain_community/llms/llamacpp.py in validate_environment(cls, values) 143 from llama_cpp import Llama, LlamaGrammar 144 except ImportError: --> 145 raise ImportError( 146 "Could not import llama-cpp-python library. " 147 "Please install the llama-cpp-python library to "
ImportError: Could not import llama-cpp-python library. Please install the llama-cpp-python library to use this embedding model: pip install llama-cpp-python`
I am facing this issue.. Can someone help me .. with colab
Use this to download depemdent files. Works for me after doing this
git clone --recursive -j8 https://github.com/abetlen/llama-cpp-python.git
https://python.langchain.com/docs/integrations/llms/llamacpp
To anyone having this problem, make sure the folder or file name you're importing llama_cpp to is not named
llama_cpporllama_cpp.py.
this indeed did the trick.
Why is that though?
By naming the script llama_cpp_xxxxx.py are we shadowing the LlamaCpp module somehow?