You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code运行含LangChain代码报ModuleNotFoundError,Python控制台正常求解

解决VS Code中运行代码提示ModuleNotFoundError: No module named 'langchain'的问题

以下是针对该问题的可行解决方案:

  • 检查VS Code使用的Python解释器
    点击VS Code左下角的Python版本指示器,确认选中的是安装了LangChain的C:\Python311\python.exe。若路径不符,点击指示器从列表中选择正确的3.11.4版本解释器。同时可在VS Code终端执行where python,对比输出路径与Python控制台中import sys; print(sys.executable)的结果是否一致。

  • 重新加载VS Code窗口
    按下Ctrl+Shift+P,输入Reload Window并执行,确保解释器切换设置生效。

  • 验证VS Code终端的环境包列表
    在VS Code终端执行pip list,检查输出中是否包含langchain。若终端激活了虚拟环境,需确认该环境是否安装了langchain,或切换到全局环境后重试。

  • 手动指定解释器路径到运行配置
    打开运行和调试面板(Ctrl+Shift+D),创建或编辑launch.json文件,添加pythonPath字段指定正确的解释器路径,示例配置:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "${file}",
                "console": "integratedTerminal",
                "pythonPath": "C:\\Python311\\python.exe"
            }
        ]
    }
    

内容的提问来源于stack exchange,提问作者anonymousqs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 15:32:11