Solidity

‘和rrno2和rrn這2Errno 2沒有這樣的文件或目錄:‘solc’’ 使用 py-solc 和solidity

  • December 18, 2021

我安裝了 py-solc 和solidity:

solc,solidity 編譯器命令行界面版本:0.4.16+commit.d7661dd9.Darwin.appleclang

並在 python 中執行此程式碼(帶有契約源範例):

from solc import compile_source, compile_files, link_code

   source = """
   pragma solidity ^0.4.2;
   contract Example {
       string s="Hello World!";
       function set_s(string new_s) {
           s = new_s;
       }
       function get_s() returns (string) {
           return s;
       }
   }"""

compiled = compile_source(source)

並且 compile_source() 函式返回了這個錯誤:

Traceback (most recent call last):
 File "<pyshell#3>", line 1, in <module>
   compile_source("pragma solidity ^0.4.0;\n contract Foo {}", output_values=["bin", 'abi'])
 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/solc/main.py", line 106, in compile_source
   stdoutdata, stderrdata, command, proc = solc_wrapper(**compiler_kwargs)
 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/solc/utils/string.py", line 85, in inner
   return force_obj_to_text(fn(*args, **kwargs))
 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/solc/wrapper.py", line 155, in solc_wrapper
   stderr=subprocess.PIPE)
 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
   restore_signals, start_new_session)
 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
   raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'solc'

如何解決這個問題並使用 py-solc 進行編譯?

問題是你的電腦上沒有安裝solc。通過安裝它

sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc

或者你可以去這裡

還有一個實驗性功能要求 py-solcsolc為您安裝:

solc可以py-solc在列出的平台上安裝以下任何版本。

  • v0.4.1(Linux)
  • v0.4.2(Linux)
  • v0.4.6(Linux)
  • v0.4.7(Linux)
  • v0.4.8(Linux/OSX)
  • v0.4.9(Linux)
  • v0.4.11(Linux/OSX)
  • v0.4.12(Linux/OSX)
  • v0.4.13(Linux/OSX)
  • v0.4.14(Linux/OSX)
  • v0.4.15(Linux/OSX)
  • v0.4.16(Linux/OSX)
  • v0.4.17(Linux/OSX)

安裝可以通過命令行完成:

$ python -m solc.install v0.4.17

引用自:https://ethereum.stackexchange.com/questions/26192