[Ethereum] “[Errno 2] No such file or directory: ‘solc’ ” Using py-solc and solidity

pythonsolcsolidity

I installed py-solc and solidity:

solc, the solidity compiler commandline interface
Version: 0.4.16+commit.d7661dd9.Darwin.appleclang

and ran this code in python (with a contract source example):

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)

and the compile_source() function returned this error:

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'

how is it possible to fix this issue and compile using py-solc?

Best Answer

The problem is solc is not installed on your pc. get it installed through

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

or you can go here

Related Topic