py-solc icon indicating copy to clipboard operation
py-solc copied to clipboard

Cannot find import file

Open ayeteng opened this issue 5 years ago • 4 comments

  • py-solc Version: 3.1.0
  • solc Version: 0.4.24
  • Python Version: 3.7
  • OS: osx

What was wrong?

  • full output of the error you received

/usr/local/bin/python3.7 /Users/sam/work/tutorial/test/web3_test.py Traceback (most recent call last): File "/Users/sam/work/tutorial/test/web3_test.py", line 80, in compiled_sol = compile_source(contract_source_code, allow_paths=PROJECT_ROOT) # Compiled source code File "/usr/local/lib/python3.7/site-packages/solc/main.py", line 108, in compile_source stdoutdata, stderrdata, command, proc = solc_wrapper(**compiler_kwargs) File "/usr/local/lib/python3.7/site-packages/solc/utils/string.py", line 85, in inner return force_obj_to_text(fn(*args, **kwargs)) File "/usr/local/lib/python3.7/site-packages/solc/wrapper.py", line 169, in solc_wrapper stderr_data=stderrdata, solc.exceptions.SolcError: An error occurred during execution > command: solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,userdoc --allow-paths /Users/sam/work/tutorial > return code: 1 > stderr:

    > stdout:
    <stdin>:2:1: Error: Source "interfaces/ISimpleStorage.sol" not found: File not found.

import './interfaces/ISimpleStorage.sol'; ^---------------------------------------^

  • the code that caused the failure There is an import in the solidity contract that I try to import another contract. But the program cannot find it.

in my python code:

contract_source_code = open('../contracts/storage/SimpleStorage.sol', 'r').read()
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
compiled_sol = compile_source(contract_source_code, allow_paths=PROJECT_ROOT)  # Compiled source code

in my SimpleStorage.sol:

pragma solidity ^0.4.24;
import './interfaces/ISimpleStorage.sol';

Tree: . ├── Migrations.sol ├── SimpleStorage.sol ├── storage │   ├── SimpleStorage.sol │   └── interfaces │    └── ISimpleStorage.sol ├── token │   ├── ERC20Token.sol │   └── interfaces │    └── IERC20Token.sol └── utility └── Utils.sol

Cute Animal Picture

cc

ayeteng avatar Jul 18 '18 08:07 ayeteng

I just encountered the same error, looking into the pysolc source code it appears like it might not be an issue with pysolc at all, but rather an issue with solidity 0.4.24 -- https://github.com/ethereum/solidity/issues/2742 describes an almost identical problem that has not yet been fixed.

theGavinBrick avatar Jul 19 '18 13:07 theGavinBrick

If I run it under terminal with command: console> solc --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,userdoc --allow-paths /Users/sam/work/tutorial ./SimpleStorage.sol It can output the correct result. I am not sure if the issue related with ethereum or py-solc.

ayeteng avatar Jul 20 '18 03:07 ayeteng

@ayeteng I got the same issue with yours . Compiling the .sol file with solc in command line is okay, but went wrong if using solc-py . I don't think it is a solidity 0.4.24 issue .

ppLorins avatar Nov 21 '18 02:11 ppLorins

had anyone solve this problem? It has troubled me several days...

whime avatar Nov 09 '19 07:11 whime