LangChain Academy課程[Foundation: Introduction to LangChain - Python]的Getting Set Up設定。
環境
Windows 11。
事前要求
OpenAPI 取得API Key。
Tavily 取額API Key。
Anthropic Claude Code取得API key。
參考「LangChain 使用LangSmith監控Agent」取得LangSmith API Key。
下載專案
在git bash輸入git clone --depth 1 https://github.com/langchain-ai/lca-lc-foundations.git下載lca-lc-foundations專案,並在該目錄下開啟cmd視窗。
建立.env
在lca-lc-foundations目錄下以cmd執行copy example.env .env。
文字編輯器或IDE開啟.env,填入以下:
OPENAI_API_KEYTAVILY_API_KEY
選填:
ANTHROPIC_API_KEYGOOGLE_API_KEYLANGSMITH_API_KEY
.env
# Manual installs for checking: uv
# Required
OPENAI_API_KEY='your_openai_api_key_here'
TAVILY_API_KEY='your_tavily_api_key_here'
# optional, only used in Module 1, Lesson 1 once
ANTHROPIC_API_KEY='your_anthropic_api_key_here'
GOOGLE_API_KEY='your_google_api_key_here'
# Optional for evaluation and tracing
LANGSMITH_API_KEY='your_langsmith_api_key_here'
# uncomment to set tracing to true when you set up your LangSmith account
# LANGSMITH_TRACING=true
LANGSMITH_PROJECT=lca-lc-foundation
# Uncomment the following if you are on the EU instance:
#LANGSMITH_ENDPOINT=https://eu.api.smith.langchain.com
建立.venv和下載依賴
在專案根目錄下輸入uv sync。
C:\..\lca-lc-foundations>uv sync
Using CPython 3.13.13
Creating virtual environment at: .venv
Resolved 232 packages in 4ms
Built lc-foundations @ file:///C:/../lca-lc-foundations
Built tavily==1.1.0
Built forbiddenfruit==0.1.4
Prepared 207 packages in 3m 36s
Installed 229 packages in 40.95s
...
驗證環境
在專案根目錄下輸入uv run python env_utils.py驗證環境正確。
C:\..\lca-lc-foundations>uv run python env_utils.py
======================================================================
PYTHON ENVIRONMENT DIAGNOSTICS
======================================================================
Python executable: C:\..\lca-lc-foundations\.venv\Scripts\python.exe
Python version: 3.13.13
Platform: win32
✅ Running in virtual environment: C:\..\lca-lc-foundations\.venv
✅ Python version 3.13.13 is in expected range (>=3.12, <3.14)
Environment paths:
sys.prefix: C:\..\lca-lc-foundations\.venv
sys.base_prefix: C:\Users\user\AppData\Roaming\uv\python\cpython-3.13-windows-x86_64-none
Virtual env: C:\..\lca-lc-foundations\.venv
✅ Virtual environment is properly activated
✅ uv is available
Manual Installs Check:
✅ uv
Environment Variables:
OPENAI_API_KEY=****5igA
TAVILY_API_KEY=****WWEL
ANTHROPIC_API_KEY=****fQAA
GOOGLE_API_KEY=your_google_api_key_here
LANGSMITH_API_KEY=****8361
LANGSMITH_PROJECT=lca-lc-foundation
...
執行Notebooks
在專案根目錄下輸入uv run jupyter lab啟動Notebooks。
C:\..\lca-lc-foundations>uv run jupyter lab
[I 2026-06-16 15:11:19.005 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2026-06-16 15:11:19.016 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2026-06-16 15:11:19.032 ServerApp] jupyterlab | extension was successfully linked.
[I 2026-06-16 15:11:19.056 ServerApp] Writing Jupyter server cookie secret to C:\Users\user\AppData\Roaming\jupyter\runtime\jupyter_cookie_secret
[I 2026-06-16 15:11:23.841 ServerApp] notebook_shim | extension was successfully linked.
[I 2026-06-16 15:11:24.514 ServerApp] notebook_shim | extension was successfully loaded.
[I 2026-06-16 15:11:24.519 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2026-06-16 15:11:24.521 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2026-06-16 15:11:24.531 LabApp] JupyterLab extension loaded from C:\..\lca-lc-foundations\.venv\Lib\site-packages\jupyterlab
[I 2026-06-16 15:11:24.531 LabApp] JupyterLab application directory is C:\..\lca-lc-foundations\.venv\share\jupyter\lab
[I 2026-06-16 15:11:24.534 LabApp] Extension Manager is 'pypi'.
[I 2026-06-16 15:11:25.086 ServerApp] jupyterlab | extension was successfully loaded.
[I 2026-06-16 15:11:25.089 ServerApp] Serving notebooks from local directory: C:\..\lca-lc-foundations
[I 2026-06-16 15:11:25.090 ServerApp] Jupyter Server 2.18.0 is running at:
[I 2026-06-16 15:11:25.091 ServerApp] http://localhost:8888/lab?token=c77bd0a51fc8bc289cdb9b769f7c852b4c475f002f0aa54f
[I 2026-06-16 15:11:25.091 ServerApp] http://127.0.0.1:8888/lab?token=c77bd0a51fc8bc289cdb9b769f7c852b4c475f002f0aa54f
[I 2026-06-16 15:11:25.092 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2026-06-16 15:11:25.158 ServerApp]
To access the server, open this file in a browser:
file:///C:/Users/user/AppData/Roaming/jupyter/runtime/jpserver-19912-open.html
Or copy and paste one of these URLs:
http://localhost:8888/lab?token=c77bd0a51fc8bc289cdb9b769f7c852b4c475f002f0aa54f
http://127.0.0.1:8888/lab?token=c77bd0a51fc8bc289cdb9b769f7c852b4c475f002f0aa54f
[I 2026-06-16 15:11:27.578 ServerApp] Skipped non-installed server(s): basedpyright, bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyrefly, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
[I 2026-06-16 15:11:32.473 LabApp] Build is up to date
按[Ctrl + C]離開。
執行Studio
將cmd目錄移到專案根目錄下的notebooks/modules-1,輸入uv run langgraph dev。
C:\..\lca-lc-foundations\notebooks\module-1>uv run langgraph dev
INFO:langgraph_api.cli:
Welcome to
╦ ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬
║ ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤
╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴ ┴ ┴
- 🚀 API: http://127.0.0.1:2024
- 🎨 Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024
- 📚 API Docs: http://127.0.0.1:2024/docs
This in-memory server is designed for development and testing.
For production use, please use LangSmith Deployment.
...
按[Ctrl + C]離開。
Excited to be taking @LangChainAI Academy’s Introduction to LangChain course! 🚀 Check it out: academy.langchain.com
沒有留言:
張貼留言