26

I m trying to print out the variable (compiled_sol) as you will see in the code below of the python file named deploy.py so I can deploy my smart contract, but I keep running at this error

*****INFO: Could not find files for the given pattern(s).
Traceback (most recent call last):
  File "C:\Users\houde\Desktop\Blockchain\solidity_projects\web3_py_simple_storage\deploy.py", line 8, in <module> 
    compiled_sol = compile_standard(
  File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\main.py", line 368, in compile_standard 
    solc_binary = get_executable(solc_version)
  File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\install.py", line 194, in get_executable
    raise SolcNotInstalled(
solcx.exceptions.SolcNotInstalled: solc 0.6.0 has not been installed. Use solcx.install_solc('0.6.0') to install. ******

I did install the solc-x via this command pip install py-solc-x so I can compile the contracts but I don't know how to upgrade the version or what to do in this case, I will leave the code for you guys down below, and thank you a lot.

from solcx import compile_standard

with open("SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()


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",
)

print("compiled_sol")

note:"the solc version 0.6.0 I m using it for the contract"

6 Answers 6

29

I'm working through this same course check this out and it will show you how to fix this error here: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/blob/main/chronological-issues-from-video.md

You just need to do the following: On the line that says

from solcx import compile_standard

We need to change it to this line:

from solcx import compile_standard, install_solc

And then, we need to add a line right before we run the compile_standard code:

install_solc("0.6.0")

Alternatively, you can install Solc first before installing solcx and it will give you the old version of solidity compiler included. so all you have to do is import from solcx.

Also I noticed in your settings array here:

"*": {"*": {"abi", "metadata", "evm.bytecode", "evm.sourceMap"}}

you used curly braces instead of square brackets so you will need to fix that before you try to compile. It needs to look like this

"*": {"*": ["abi", "metadata", "evm.bytecode", "evm.sourceMap"]}
1
  • Thank you a lot for helping, yes indeed for the arrays I didn't really pay attention until the JSON error popped up, I wish you good luck on the journey Sep 26, 2021 at 6:36
4

you did not import install_solc. Do it, and install the version you want

from solcx import compile_standard, install_solc

install_solc("0.6.0")

i would recommend using a framework like brownie to avoid such problems. You dont really need to do everything by yourself if you have brownie. https://github.com/eth-brownie/brownie

1

Here is your answer: Install Old Solc Compiler Versions

You just need to import the function you're going to call

0
0

3:43:52 Installing solcx version 0.6.0

In the video, we forgot to do 2 things in order to compile our solidity code:

Import install_solc, so we need to change this line:

from solcx import compile_standard

To this line:

from solcx import compile_standard, install_solc

And then, we need to add a line right before we run the compile_standard code:

(in terminal) install_solc("0.6.0")

0

The error you get says:

INFO: Could not find files for the given pattern(s). Traceback (most recent call last): File "C:\Users\houde\Desktop\Blockchain\solidity_projects\web3_py_simple_storage\deploy.py", line 8, in compiled_sol = compile_standard( File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\main.py", line 368, in compile_standard solc_binary = get_executable(solc_version) File "C:\Users\houde\AppData\Roaming\Python\Python39\site-packages\solcx\install.py", line 194, in get_executable raise SolcNotInstalled( solcx.exceptions.SolcNotInstalled: solc 0.6.0 has not been installed. Use solcx.install_solc('0.6.0') to install.

The last line is telling you what to do. Therefore use this code:

from solcx import compile_standard, install_solc # <- import the install_solc method!
install_solc('0.6.0') # <- Add this line and run it at least once!

with open("SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()


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",
)

print("compiled_sol")
0

I too am following same course and kept having same error even after following all the recommended steps above so far. finally resolve it by doing

npm install -g solc

now it's all up to you whether to install solc globally or not

Not the answer you're looking for? Browse other questions tagged or ask your own question.