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

Python中Solc安装异常:SolcNotInstalled错误求助

解决SolcNotInstalled错误的方案

问题根源

你代码中已经调用了install_solc("0.6.0"),但compile_source函数没有指定使用这个安装好的版本,solcx会默认尝试寻找系统全局安装的solc,而你环境里没有对应版本,因此触发错误。

解决方案

方案一:编译时指定solc版本

修改compile_source_file函数,在compile_source中添加solc_version参数,明确指定使用已安装的0.6.0版本:

def compile_source_file(file_path):
   with open(file_path, 'r') as f:
      source = f.read()

   return compile_source(source, output_values=['abi','bin'], solc_version="0.6.0")

方案二:设置全局默认solc版本

在调用install_solc之后,添加set_solc_version语句,将已安装的版本设为全局默认:

from solcx import compile_standard, install_solc, set_solc_version
install_solc("0.6.0")
set_solc_version("0.6.0")  # 添加该行指定默认版本

额外验证

确保你的contract.sol文件开头的版本声明和安装的版本匹配,比如:

pragma solidity ^0.6.0;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 02:00:30