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

Lesson 4: "No module named solcx".

Open MarcoNValenzuela opened this issue 2 years ago • 3 comments

Hi there, I realize a similar question was raised by another user but they seem to have found a solution which doesn't work for me. The other solution was posted here: https://github.com/smartcontractkit/full-blockchain-solidity-course-py/issues/1473.

I am using Windows, Python version 3.10.5. I use "pip install py-solc-x" on my terminal and it seems to install properly ("requirements already satisfied"), but when I run "from solcx import compile_standard" on a python file, it gives me the "No module named solcx" error. I can import other modules such as numpy fine. I also checked, and I am pretty sure I have the Solidity extension installed on Visual Studio Code.

Heres the text which appears over the code, it says "Import "solcx" could not be resolved Pylance(reportMissingImports)" image I can only guess what this exactly means.

Running the "help(modules)" command, I cant see solcx on the list of modules it gives, so maybe I'm installing it to the wrong place somehow? This seems to me like a very specific issue that is going to be different for every user

So I suppose my strategy to solving this is: Where should solcx be? Is the "from" command looking in the right place? How do I change where the "from" command is looking for modules? Am I installing solcx to the wrong place? If so, how do I change the installation path. Maybe the solcx command should be preceded by something akin to a file path, indicating where Python should look for it?

Any pointers would be appreciated :)

MarcoNValenzuela avatar Jun 24 '22 12:06 MarcoNValenzuela

I am having the same exact issue.

I ran "pip install py-solc-x" again and it says everything already installed.

I have had this sort of trouble with VS code in the past. Might be some sort of PATH issue

twooten1105 avatar Jun 24 '22 18:06 twooten1105

Oh wait. I got it to work. Copy past this exact code and see if it works:

from solcx import compile_standard, install_solc

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

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

twooten1105 avatar Jun 24 '22 18:06 twooten1105

hey, pls check if this will help you.

https://stackoverflow.com/questions/70326346/vscode-doesnt-recognize-py-solc-x-doesnt-library

Kipkurui-mutai avatar Jun 29 '22 20:06 Kipkurui-mutai