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

安装web3-ethereum-defi[data]遇编译错误,已装VC++仍未解决

解决pip安装web3-ethereum-defi[data]时的VC++编译错误

问题重现

执行命令:

pip install "web3-ethereum-defi[data]"

出现编译错误,提示需要Microsoft Visual C++ 14.0及以上版本,即使已安装Visual Studio Build Tools 2022并勾选「Desktop development with C++」组件。核心错误日志:

Building wheel for pyethash (pyproject.toml) ... error
error: Microsoft Visual C++ 14.0 or greater is required.
...
Building wheel for pysha3 (pyproject.toml) ... error
error: Microsoft Visual C++ 14.0 or greater is required.

解决方案

按顺序尝试以下步骤:

1. 使用VS官方终端执行安装命令

普通CMD/PowerShell不会自动加载VC编译环境,必须打开x64 Native Tools Command Prompt for VS 2022(开始菜单搜索即可找到),在该终端内重新运行pip安装命令。此终端会自动配置所有必要的VC环境变量。

2. 检查Build Tools组件完整性

打开Visual Studio Installer,修改已安装的Build Tools 2022,确保以下组件已勾选:

  • Desktop development with C++ 主组件
  • 子组件:
    • MSVC v143 - VS 2022 C++ x64/x86 build tools(匹配你的系统架构,优先选x64)
    • Windows 11/10 SDK(对应你的操作系统版本)
    • C++ CMake tools for Windows
      安装完成后重启电脑。

3. 安装预编译wheel包跳过编译

pyethash和pysha3提供预编译的wheel包,可先单独安装这两个包避免编译:

pip install --only-binary :all: pyethash pysha3

完成后再执行原安装命令:

pip install "web3-ethereum-defi[data]"

4. 验证Python与工具集架构匹配

确保Python版本与VC++工具集架构一致(如均为x64),执行以下命令检查Python位数:

python -c "import sys; print(sys.maxsize > 2**32)"

返回True为64位,False为32位。若架构不匹配,需更换对应架构的Python或VC++工具集。

5. 手动配置环境变量(可选)

若不想使用VS终端,可手动将VC++工具集的bin目录添加到系统PATH:

  • 找到VC++ bin路径,示例:C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\[你的版本号]\bin\Hostx64\x64
  • 将该路径添加到系统环境变量PATH,重启终端后重试安装。

内容的提问来源于stack exchange,提问作者Hao Tan Truong

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 07:52:46