ImportError / ModuleNotFoundError
builtins.ModuleNotFoundError: No module named 'langchain_google_genai'
Stack trace
Traceback (most recent call last):
File "app.py", line 5, in <module>
from langchain_google_genai import ChatGoogleGenerativeAI
ModuleNotFoundError: No module named 'langchain_google_genai' Why it happens
LangChain split its integrations into separate packages starting in v0.1.0. ChatGoogleGenerativeAI lives in the langchain_google_genai package, not in the core langchain package. If you install only langchain without installing langchain_google_genai, the import fails. This is intentional: it keeps dependencies minimal and lets you install only the integrations you use.
Detection
Check your import statement before running: verify you're importing from langchain_google_genai, not langchain. Run pip list | grep langchain to confirm langchain_google_genai is installed in your environment.
Causes & fixes
langchain_google_genai package is not installed: only langchain core is installed
Run: pip install langchain_google_genai. This installs the Google Generative AI integration for LangChain, including ChatGoogleGenerativeAI.
Wrong import path: importing from langchain instead of langchain_google_genai
Change: from langchain.chat_models import ChatGoogleGenerativeAI to from langchain_google_genai import ChatGoogleGenerativeAI (correct v0.1+ path)
Virtual environment issue: package installed globally but not in active venv
Activate your virtual environment: source venv/bin/activate (Linux/Mac) or venv\Scripts\activate (Windows), then run pip install langchain_google_genai again.
Conflicting or outdated version of langchain_google_genai installed
Run: pip install --upgrade langchain_google_genai to get the latest compatible version that matches your langchain version.
Code: broken vs fixed
# BROKEN: This import path doesn't exist in LangChain v0.1+
from langchain.chat_models import ChatGoogleGenerativeAI # ← ModuleNotFoundError
from langchain.schema import HumanMessage
import os
api_key = os.environ.get('GOOGLE_API_KEY')
chat = ChatGoogleGenerativeAI(google_api_key=api_key, model='gemini-2.0-flash') # FIXED: Correct import from langchain_google_genai package
from langchain_google_genai import ChatGoogleGenerativeAI # ← FIX: Use langchain_google_genai, not langchain
from langchain.schema import HumanMessage
import os
api_key = os.environ.get('GOOGLE_API_KEY')
chat = ChatGoogleGenerativeAI(google_api_key=api_key, model='gemini-2.0-flash')
# Test the import worked
message = HumanMessage(content='Hello')
response = chat.invoke([message])
print('Import successful:', response.content[:50]) Workaround
If you cannot install langchain_google_genai immediately, use the Google Generative AI SDK directly without LangChain: import google.generativeai as genai; genai.configure(api_key=os.environ['GOOGLE_API_KEY']); model = genai.GenerativeModel('gemini-2.0-flash'). This bypasses LangChain entirely and works without any additional packages beyond google-generativeai.
Prevention
In new projects, always install the specific LangChain integration packages you need upfront: pip install langchain langchain_google_genai. Document your dependencies in requirements.txt or pyproject.toml and ensure they include both langchain and langchain_google_genai. Use pip freeze > requirements.txt after installation to lock exact versions and share with your team.