Dependency issue on Langchain - langchain.prompts import PromptTemplate
Describe the bug Langchain dependency error:
.venv\Lib\site-packages\scrapegraphai\utils\code_error_analysis.py", line 15, in <module>
from langchain.prompts import PromptTemplate
ModuleNotFoundError: No module named 'langchain.prompts'
To Reproduce Steps to reproduce the behavior:
- python -m venv .venv
- source .venv/Scripts/activate
- Fresh installation - pip install scrapegraphai
run script:
try: from scrapegraphai.graphs import SmartScraperGraph print("Import successful: SmartScraperGraph imported successfully") except ImportError as e: print(f"Import failed: {e}") except Exception as e: print(f"Unexpected error during import: {e}")
output: python test_import.py Import failed: No module named 'langchain.prompts'
Expected behavior All dependencies should be available
Screenshots N/A
Desktop (please complete the following information):
- OS: Windows
- Browser: NA
- Version: 10
Additional context pip list
Package Version aiohappyeyeballs 2.6.1 aiohttp 3.13.1 aiosignal 1.4.0 annotated-types 0.7.0 anyio 4.11.0 async-timeout 5.0.1 attrs 25.4.0 beautifulsoup4 4.14.2 boto3 1.40.57 botocore 1.40.57 certifi 2025.10.5 charset-normalizer 3.4.4 click 8.3.0 colorama 0.4.6 dataclasses-json 0.6.7 dill 0.4.0 distro 1.9.0 duckduckgo_search 8.1.1 filelock 3.20.0 free_proxy 1.1.3 frozenlist 1.8.0 fsspec 2025.9.0 greenlet 3.2.4 h11 0.16.0 html2text 2025.4.15 httpcore 1.0.9 httpx 0.28.1 httpx-sse 0.4.3 huggingface-hub 0.35.3 idna 3.11 jiter 0.11.1 jmespath 1.0.1 jsonpatch 1.33 jsonpointer 3.0.0 jsonschema 4.25.1 jsonschema-specifications 2025.9.1 langchain 1.0.2 langchain-aws 1.0.0 langchain-classic 1.0.0 langchain-community 0.4 langchain-core 1.0.0 langchain-mistralai 1.0.0 langchain-ollama 1.0.0 langchain-openai 1.0.1 langchain-text-splitters 1.0.0 langgraph 1.0.1 langgraph-checkpoint 3.0.0 langgraph-prebuilt 1.0.1 langgraph-sdk 0.2.9 langsmith 0.4.37 lxml 6.0.2 marshmallow 3.26.1 minify_html 0.16.4 mpire 2.10.2 multidict 6.7.0 multiprocess 0.70.18 mypy_extensions 1.1.0 numpy 2.3.4 ollama 0.6.0 openai 2.6.0 orjson 3.11.3 ormsgpack 1.11.0 packaging 25.0 pip 24.0 playwright 1.55.0 primp 0.15.0 propcache 0.4.1 pydantic 2.12.3 pydantic_core 2.41.4 pydantic-settings 2.11.0 pyee 13.0.0 Pygments 2.19.2 python-dateutil 2.9.0.post0 python-dotenv 1.1.1 pywin32 311 PyYAML 6.0.3 referencing 0.37.0 regex 2025.10.23 requests 2.32.5 requests-toolbelt 1.0.0 rpds-py 0.28.0 s3transfer 0.14.0 scrapegraph_py 1.36.0 scrapegraphai 1.63.0 semchunk 3.2.3 simpleeval 1.0.3 six 1.17.0 sniffio 1.3.1 soupsieve 2.8 SQLAlchemy 2.0.44 tenacity 9.1.2 tiktoken 0.12.0 tokenizers 0.22.1 tqdm 4.67.1 typing_extensions 4.15.0 typing-inspect 0.9.0 typing-inspection 0.4.2 undetected-playwright 0.3.0 urllib3 2.5.0 xxhash 3.6.0 yarl 1.22.0 zstandard 0.25.0
Hi @rosh7777! I'm Dosu and I’m helping the Scrapegraph-ai team.
The error happens because recent versions of langchain (like 1.0.2) have removed or reorganized the langchain.prompts module, so PromptTemplate is no longer available at that import path. scrapegraphai 1.63.0 still tries to import it from langchain.prompts, which causes the failure. This is a known compatibility issue—scrapegraphai expects an older langchain structure that no longer exists in 1.x+ releases.
There’s no official patch or workaround for this in the latest scrapegraphai. The most reliable options are to either downgrade langchain to a version where langchain.prompts.PromptTemplate still exists (pre-1.0.0), or to use a version of scrapegraphai that is confirmed to work with your installed langchain version. Community reports suggest that scrapegraphai 1.37.0 or 1.40.1 work with older langchain versions, but not with 1.x+ source.
If you need to use the latest langchain, you’ll have to wait for scrapegraphai to update its imports and compatibility, or patch the import paths in your local installation.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other
same Q!
same Q!
same q
Try this, it is restructured to langchain_core from langchain_core.prompts import PromptTemplate
Summary received from chat GPT (I used 2 of them and worked for me)
| Old Import (pre-v1.0 | New Import (v1.0+) | Required Package |
|---|---|---|
| from langchain.prompts import PromptTemplate | from langchain_core.prompts import PromptTemplate | langchain-core |
| from langchain.text_splitter import RecursiveCharacterTextSplitter | from langchain_text_splitters import RecursiveCharacterTextSplitter | langchain-text-splitters |
| from langchain.llms import OpenAI | from langchain_community.llms import OpenAI | langchain-community |
| from langchain.embeddings import HuggingFaceEmbeddings | from langchain_huggingface import HuggingFaceEmbeddings | langchain-huggingface |
Solution: LangChain v1.0+ Compatibility
I was able to solve this by creating a compatibility shim that bridges scrapegraphai with LangChain v1.0+. The issue is that scrapegraphai imports from old LangChain paths that were reorganized in v1.0+.
Quick Fix
Create a file langchain_compat.py:
"""Compatibility helpers for newer LangChain package layouts."""
from __future__ import annotations
import importlib, sys
from types import ModuleType
from typing import Tuple
_ALIASES: Tuple[Tuple[str, str], ...] = (
("langchain.prompts", "langchain_core.prompts"),
("langchain.output_parsers", "langchain_core.output_parsers"),
("langchain.chat_models", "langchain_community.chat_models"),
("langchain.llms", "langchain_community.llms"),
("langchain.embeddings", "langchain_community.embeddings"),
("langchain.text_splitter", "langchain_text_splitters"),
)
def _load_module(target: str) -> ModuleType | None:
try:
return importlib.import_module(target)
except ImportError:
return None
def ensure_langchain_compat() -> None:
for legacy_path, modern_path in _ALIASES:
if legacy_path in sys.modules or _load_module(legacy_path):
continue
modern_module = _load_module(modern_path)
if modern_module is not None:
sys.modules[legacy_path] = modern_module
_patch_chat_models()
_patch_output_parsers()
_patch_openai()
def _patch_chat_models() -> None:
try:
from langchain_community.chat_models import ChatOpenAI
if "langchain.chat_models" not in sys.modules:
sys.modules["langchain.chat_models"] = ModuleType("langchain.chat_models")
sys.modules["langchain.chat_models"].ChatOpenAI = ChatOpenAI
except ImportError:
pass
def _patch_output_parsers() -> None:
try:
from langchain_community.output_parsers import ResponseSchema, StructuredOutputParser
import langchain_core.output_parsers
langchain_core.output_parsers.ResponseSchema = ResponseSchema
langchain_core.output_parsers.StructuredOutputParser = StructuredOutputParser
except ImportError:
pass
def _patch_openai() -> None:
try:
from langchain_community.chat_models.openai import ChatOpenAI
original = ChatOpenAI.completion_with_retry
def patched(self, **kwargs):
kwargs.pop("model_provider", None)
return original(self, **kwargs)
ChatOpenAI.completion_with_retry = patched
except Exception:
pass
Then in your script, load it before importing scrapegraphai:
from langchain_compat import ensure_langchain_compat
ensure_langchain_compat()
from scrapegraphai.graphs import SmartScraperGraph
graph_config = {
"llm": {
"api_key": "your-key",
"model": "openai/gpt-4o-mini", # Use provider/model format
},
}
有解决吗?