Installation and Verification
- Install LangChain, langchain-core, and langchain-text-splitters.
1python3 -m pip install langchain langchain-core langchain-text-splitters
- After the installation is complete, record the actual version.
1python3 -m pip show langchain langchain-core langchain-text-splitters
- Check whether LangChain is successfully installed.
- Create the verification script validate_langchain_basic.py.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import langchain import langchain_core from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableLambda from langchain_text_splitters import RecursiveCharacterTextSplitter def validate_imports(): print("langchain=" + langchain.__version__) print("langchain_core=" + langchain_core.__version__) def validate_runnable(): runnable = RunnableLambda(lambda value: value + 1) result = runnable.invoke(1) assert result == 2 print("runnable_result=" + str(result)) def validate_prompt(): prompt = ChatPromptTemplate.from_template("Hello, {name}!") messages = prompt.format_messages(name="ARM") assert len(messages) == 1 assert "ARM" in messages[0].content print("prompt_result=" + messages[0].content) def validate_text_splitter(): splitter = RecursiveCharacterTextSplitter(chunk_size=20, chunk_overlap=5) chunks = splitter.split_text("LangChain runs successfully on ARM platform.") assert len(chunks) > 0 print("chunk_count=" + str(len(chunks))) if __name__ == "__main__": validate_imports() validate_runnable() validate_prompt() validate_text_splitter() print("LangChain basic validation passed")
- Perform the verification.
1python3 validate_langchain_basic.py
The following is the expected output.
1 2 3 4 5 6
langchain= langchain_core= runnable_result=2 prompt_result=Hello, ARM! chunk_count= LangChain basic validation passed
- Create the verification script validate_langchain_basic.py.
Acceptance Criteria
The basic compatibility verification is passed if the following items are met.
Item |
Check Criteria |
|---|---|
Installation |
LangChain, langchain-core, and langchain-text-splitters can be installed using pip. |
Import |
No exception occurs when importing langchain and langchain_core. |
Runnable |
RunnableLambda can be executed properly and return the expected result. |
Prompt |
ChatPromptTemplate can format messages properly. |
Text splitter |
RecursiveCharacterTextSplitter can split text properly. |
FAQs
If the installation fails, check whether the Python version meets the dependency requirements.
1 2 3 | python3 --version python3 -m pip index versions langchain python3 -m pip index versions langchain-core |
If a message is displayed indicating that the wheel fails to be built, record the complete error log and pay attention to the following information:
Information |
Description |
|---|---|
Python version not meeting requirements |
You need to replace the Python version with one that meets the dependency requirements. |
Build tool missing |
You may need to install build dependencies such as GCC and python3-devel. |
No Arm wheel |
The dependency package may not provide the wheel for the current platform. You need to build the wheel using the source code. |
The basic verification should not proactively introduce dependencies such as vector databases, document parsing, embedding, and external model calling. If these dependencies report errors, handle them separately as extended verification issues.