langchain: AttributeError: module 'langchain' has no attribute 'verbose'
System Info
274 Mac M2
this error appears often and unexpectedly but gets solved temporarily by running a force reinstall
pip install --upgrade --force-reinstall --no-deps --no-cache-dir langchain
full error
2023-08-28 08:16:48.197 Uncaught app exception
Traceback (most recent call last):
File "/Users/user/Developer/newfilesystem/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
exec(code, module.__dict__)
File "/Users/user/Developer/newfilesystem/pages/chat.py", line 104, in <module>
llm = ChatOpenAI(
File "/Users/user/Developer/newfilesystem/venv/lib/python3.10/site-packages/langchain/load/serializable.py", line 74, in __init__
super().__init__(**kwargs)
File "pydantic/main.py", line 339, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 1066, in pydantic.main.validate_model
File "pydantic/fields.py", line 439, in pydantic.fields.ModelField.get_default
File "/Users/user/Developer/newfilesystem/venv/lib/python3.10/site-packages/langchain/chat_models/base.py", line 49, in _get_verbosity
return langchain.verbose
main librairies in the project requests streamlit pandas colorlog python-dotenv tqdm fastapi uvicorn langchain openai tiktoken chromadb pypdf colorlog logger docx2txt
Who can help?
Information
- The official example notebooks/scripts
- My own modified scripts
Related Components
- LLMs/Chat Models
- Embedding Models
- Prompts / Prompt Templates / Prompt Selectors
- Output Parsers
- Document Loaders
- Vector Stores / Retrievers
- Memory
- Agents / Agent Executors
- Tools / Toolkits
- Chains
- Callbacks/Tracing
- Async
Reproduction
intermittent - no pattern
Expected behavior
resolution
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 2
- Comments: 26 (1 by maintainers)
you’re right, all bets are off if a user does
import langchain
and get their own module instead of langchain-ai/langchain.however, i ran into this w/ code that was using
import langchain_core
and tripping over alangchain/
in my working directory.@obi1kenobi the
import langchain
inget_verbose
andget_debug
is pulling in the user’slangchain
module.this will also happen for
get_llm_cache
.the
langchain_core/globals/__init__.py
code couldexcept AttributeError
to protect from this. it could also raise a warning to the user that they’re masking thelangchain
module with their own.i ran into this because i had a clone of langchain in my current working directory.
Renaming
langchain.py
tomain.py
fixed it!Is it possible that the app is running inside a different virtualenv than where you added the print statements? I think something like that is the only possible answer here because of the printout value you showed earlier:
This was obtained by reading
langchain.verbose
, which is the value that the crashing code says doesn’t exist. But it clearly exists with valueFalse
here, so it has to be the case that the error is coming from some other process which is invoking langchain in a different (probably outdated) virtualenv.Going back through your previous messages, it seems like there might indeed be two virtualenvs at different paths and with different versions: one in python 3.9 and one in python 3.10.
Could you look through your machine (and your previous messages here) and make sure to run the
pip freeze
andpipdeptree
commands in both virtualenvs? Here are the full commands one more time, for your convenience: