这是代码
from solcx import compile_standard, install_solc
import json
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)在终端中,我运行了:pip3 install py-solc-x和pip install solc的命令,并得到了一个响应,即这两个命令已经分别满足了需求。
我还得到了INFO:无法找到给定模式的文件的错误。当我运行python deploy.py命令时
这就是在本地磁盘上by VS Code文件夹的样子:python源文件和SOL文件位于同一个文件夹中。
正如您可能知道的,我是非常新的,因为我正在参加freeCodeCamps初学者课程。任何和所有的帮助都是非常感谢的,谢谢你提前。
发布于 2022-03-01 15:05:41
这是为了解决第一个错误:通过运行“停用”(或从Anaconda虚拟环境中退出的"conda禁用“)从任何虚拟环境中退出。
从终端运行python3
按以下方式运行以下代码行:
import solcx
solcx.install_solc() #or you can install a specific version by running "solcx.install_solc('0.6.0')"(without the quotes) or any other version in the brackets.至于第二个错误,请检查SimpleStorage.sol文件是否与给定的python代码文件位于同一个目录中。而且,"compiled_code.json“文件将与给定的python文件在同一个文件夹中自动创建(由于打开函数中的"w”参数)。
发布于 2022-01-21 08:23:51
你能检查一下你在哪里安装了模块吗?pip3 show py-solc-x。
并检查您从VSCode的左下角选择了哪个python解释器:

您可以单击它来选择python解释器,或者在您选择的环境中重新安装模块。
从你的形象来看,你的文件名有点奇怪。您的文件名为SimpleStorage.sol,而另一个文件名为deploy,其类型为Python Source File。所以你看起来好像隐藏了文件扩展名,所以你的文件名需要是SimpleStorage。
发布于 2022-05-14 07:03:16
进口solcx
solcx.install_solc("0.6.0")
这对我来说很管用
https://stackoverflow.com/questions/70792187
复制相似问题