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

VSCode中Python环境安装web3时出现lru-dict依赖安装报错

问题现象

在VSCode绑定的Python 3.10环境中安装web3库时,依赖包lru-dict安装失败,完整报错输出如下:

Running setup.py install for lru-dict ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for lru-dict did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      running install
      C:\Users\acer\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'lru' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools"
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lru-dict

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
报错根因
  • 核心触发原因:lru-dict包含C语言编写的扩展模块,走源码安装流程时需要本地编译环境支持,当前系统缺少版本号≥14.0的Microsoft Visual C++生成工具,编译步骤直接中断导致安装失败。
  • 日志里的setup.py install is deprecated是setuptools的版本弃用警告,不属于致命错误,不是本次安装失败的核心原因,无需单独处理。
解决方案

按操作成本从低到高排序,任选一种即可解决:

  • 方案1:升级pip拉取预编译包(操作最快,无需安装额外大体积软件)
    1. 先执行命令升级pip、setuptools、wheel组件,旧版本pip默认拉取源码包触发本地编译,新版本会自动匹配对应系统、Python版本的预编译二进制whl包,跳过编译步骤:
      pip install --upgrade pip setuptools wheel
    2. 升级完成后重新执行web3安装命令即可:
      pip install web3
  • 方案2:安装本地C++编译环境(治本方案,适合后续需要频繁安装带C扩展Python包的场景)
    1. 获取Microsoft C++ Build Tools安装程序后运行,勾选「使用C++的桌面开发」工作负载
    2. 确认安装项包含MSVC v14及以上版本生成工具、对应系统版本的Windows SDK
    3. 等待安装完成后重启设备,重新执行pip install web3即可正常安装。
  • 方案3:固定lru-dict版本安装(备用方案,前两种方案失效时使用)
    部分新版本lru-dict未提供对应Python版本的预编译包,可先安装已提供预编译包的稳定低版本,再安装web3,依次执行以下命令:
    pip install lru-dict==1.1.8
    pip install web3
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.28 14:09:23