'VS Code 2 errors: 1st is "Import 'solcx' could not be resolved." 2nd issue is given in terminal as "INFO: Could not find files for the given patterns

Here is the code

from solcx import compile_standard, install_solc
import json

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

with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

In the terminal, I have ran the commands of: pip3 install py-solc-x and pip install solc and get a response that the requirement is already satisfied separately for both commands.

I also get the error of INFO: Could not find files for the given pattern(s). when I run the command of python deploy.py

This is how by VS Code folder looks like on my Local Disk: the python source file and SOL file are in the same folder

As you can probably tell, I am very new as I'm taking freeCodeCamps beginners course. Any and all help is great appreciated, thank you in advance.



Solution 1:[1]

This is for resolving the first error: Exit from any virtual environments by running "deactivate" (or "conda deactivate" for exiting from an Anaconda virtual environment).

Run python3 from the terminal

Run these lines of code as follows:

  import solcx

  solcx.install_solc() #or you can install a specific version by running "solcx.install_solc('0.6.0')"(without the quotes) or any other version in the brackets.

As for the second error, check if the SimpleStorage.sol file is present in the same directory as the given python code file. And also the "compiled_code.json" file will automatically be created in the same folder as that of the given python file(due to the "w" argument present in the open function).

Solution 2:[2]

Could you check where you have installed the modules? pip3 show py-solc-x.

And check which python interpreter you have selected from the bottom-left on the VSCode:

enter image description here

You can click it to select the python interpreter or reinstall the modules in the environment you have selected.

And from your image, it's a little weird about your filename. Your file was named SimpleStorage.sol while another file was named deploy and its type was Python Source File. So you look like have hidden the filename extension, so your file name needs to be SimpleStorage.

Solution 3:[3]

import solcx

solcx.install_solc("0.6.0")

this worked for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Steven-MSFT
Solution 3 Jai Bhasin