惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - 木乃伊人

VSCode Unable to import XXX 问题解决记录 大模型应用开发-聊天机器人-保存聊天记录 try-catch中的throw和throw ex的区别 TDD Google Chrome 默认非安全端口列表 EF Core的预先加载、延迟加载、实体追踪 同步、异步、回调 软件设计原则 UML类图 Seq Serilog 多线程整理 Vuex和Pinia Vue3+TS+Vite+pinia 枚举 Vite创建Vue3项目 闭包 IdentitySrever4 ElasticSearch 前端防止重复提交案例
VS Code 搭建LangChain开发环境
木乃伊人 · 2026-05-26 · via 博客园 - 木乃伊人

一、简介

接下来,我们将在本地使用VS Code 的python虚拟环境来搭建一个LangChain开发环境。

二、步骤

2.1、创建并激活python虚拟环境

电脑上新建文件夹 “65-AgentDemo”,然后打开VS Code终端,用以下命令来创建一个新的Python虚拟环境。

# 创建名为 .venv 的虚拟环境
python -m venv .venv

# 激活虚拟环境
# windows(PowerShell)
.venv\Scripts\activate

# Linux/macOS:
source .venv/bin/activate

激活后,命令行出现 .venv 字样,如下图所示:

image

2.2、安装LangChain核心库

LangChain 被设计为模块化的。我们将安装 langchain (核心), langchain-openai (与OpenAI模型交互) 和 langchain-community (社区维护的集成)。

# 使用国内镜像源加速安装
pip install langchain langchain-openai langchain-community -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

2.3、安装常用依赖-以RAG为例

一个非常常见的应用场景是RAG (Retrieval-Augmented Generation),即基于外部文档的问答。这通常需要额外的依赖:

tiktoken: OpenAI 用于计算文本 token 数量的工具。
chromadb一个开源的向量数据库,用于存储文档嵌入向量
faiss-cpu: Facebook AI 开发的高效向量相似度搜索库。
python-dotenv: 用于从 .env 文件中加载环境变量 (如 API 密钥)。

pip install tiktoken chromadb faiss-cpu python-dotenv -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

2.4、验证开发环境

最后,我们创建一个简单的 Python 脚本 test.py 来验证所有安装是否成功。

import sys
import langchain
import openai

# 打印已安装库的版本
print(f"LangChain version: {langchain.__version__}")
print(f"OpenAI version: {openai.__version__}")

# 打印 Python 解释器版本
print(f"Python version: {sys.version}")

终端中输入以下命令运行test.py

得到以下结果,就说明开发环境已经搭建好。

image