full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

Lesson 4 - Error using solcx - No module named solcx

Open anuragpagaria opened this issue 3 years ago • 9 comments

Hey, Even after applying the fix that you folks have suggested, the error remains the same

As mentioned earlier I have changed the 1st line to - from solcx import compile_standard, install_solc

and also added - install_solc("0.6.0")

Using pip install py-solc-x to install solcx in the terminal window

What am I missing over here?

Thanks for our help

anuragpagaria avatar Jan 23 '22 07:01 anuragpagaria

you don't need to do it using "pip install", just write the code "install_solc("0.6.0")" in the deploy.py file before the line compiled_sol = compile_standard()

also make sure your import install_solc in the first line

hrmnswrld avatar Jan 23 '22 07:01 hrmnswrld

Hey, thanks for replying, Yes I have done that. Here is my code snippet

from solcx import compile_standard, install_solc

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.bytecode.sourceMap"]
                }
            }
        },
    },
    solc_version="0.6.0",
)
print(compiled_sol)

And in the terminal window

Before running this code - pip install py-solc-x

After that Python deploy.py

I am not able to debug what am I missing.

Thanks for your help

anuragpagaria avatar Jan 23 '22 08:01 anuragpagaria

Hello @anuragpagaria on your vscode bottom left corner, you will have the python interpreter you are using, be sure to select the one on where you have installed py-solc-x

cromewar avatar Jan 24 '22 02:01 cromewar

@anuragpagaria : I had the same problem as you and found that using the command python3 deploy.py fixed my problem.

gaussiao avatar Jan 25 '22 06:01 gaussiao

Does @gaussiao solution work for you @anuragpagaria ?

cromewar avatar Jan 25 '22 13:01 cromewar

Most likely @cromewar is correct. Please have a look on how VSC is helping with virtual python environments https://code.visualstudio.com/docs/python/environments First you should create a virtual env in your project directory with on Mac python3 -m venv .venv on Windows python -m venv .venv

VSC will ask you to use this venv for your workspace, choose "yes" (important!) Close the terminal in VSC and open a new one, now you should see (.venv) in every new line on your terminal. Check if solcx is already installed here with pip freeze if its not in the list (expected) than install it with pip install py-solc-x

This way you will have a nice and clean python environment everytime you work in this workspace and installations or worse "uninstallation" in the global python environment won't mess with your project.

n4n0b1t3 avatar Jan 31 '22 11:01 n4n0b1t3

You are awesome @n4n0b1t3

cromewar avatar Jan 31 '22 14:01 cromewar

for me it was changing the two lines others had mentioned, but I also had to use "python3 deploy.py" instead of the command in the video.

snowieoxs avatar Feb 14 '22 02:02 snowieoxs

I added install_solc("0.6.0")

and then used "python3 deploy.yp" in the terminal and it worked! thanks all

sillytechie avatar Mar 30 '22 21:03 sillytechie