ApeWorX / py-solc-x

Python wrapper and version management tool for the solc Solidity compiler.
https://solcx.readthedocs.io/
MIT License
138 stars 48 forks source link

Trouble with Solc Installation in Python: SolcNotInstalled Error #166

Open abhishek165 opened 7 months ago

abhishek165 commented 7 months ago

Environment information

python3 -m venv env source env/bin/activate pip3 install py-solc-x

What went wrong?

I am encountering an issue while trying to run a Python script that involves Solidity compilation. Specifically, I am getting a SolcNotInstalled error.

Deployment Attempt: I attempted to deploy a smart contract using the web3.py library by following documentation. I used the provided code exactly as shown in the documentation. My expectation was that the smart contract code would be deployed successfully, but it threw the SolcNotInstalled error.

Documentation Code Execution: I executed the code provided in the documentation without any modifications. However, the execution resulted in the SolcNotInstalled error.

Environment Setup: I have created a dedicated environment for my project and installed all the necessary libraries and dependencies, including web3.py and solcx.

Code: ''' import sys import time import pprint

from web3.providers.eth_tester import EthereumTesterProvider from web3 import Web3 from eth_tester import PyEVMBackend from solcx import compile_source

from solcx import compile_standard, install_solc install_solc("0.6.0")

def compile_source_file(file_path): with open(file_path, 'r') as f: source = f.read()

return compile_source(source,output_values=['abi','bin'])

def deploy_contract(w3, contract_interface): tx_hash = w3.eth.contract( abi=contract_interface['abi'], bytecode=contract_interface['bin']).constructor().transact()

address = w3.eth.get_transaction_receipt(tx_hash)['contractAddress']
return address

w3 = Web3(EthereumTesterProvider(PyEVMBackend()))

contract_source_path = 'contract.sol' compiled_sol = compile_source_file('contract.sol')

contract_id, contract_interface = compiled_sol.popitem()

address = deploy_contract(w3, contract_interface) print(f'Deployed {contract_id} to: {address}\n')

store_var_contract = w3.eth.contract(address=address, abi=contract_interface["abi"])

gas_estimate = store_var_contract.functions.setVar(255).estimate_gas() print(f'Gas estimate to transact with setVar: {gas_estimate}')

if gas_estimate < 100000: print("Sending transaction to setVar(255)\n") tx_hash = store_var_contract.functions.setVar(255).transact() receipt = w3.eth.wait_for_transaction_receipt(tx_hash) print("Transaction receipt mined:") pprint.pprint(dict(receipt)) print("\nWas transaction successful?") pprint.pprint(receipt["status"]) else: print("Gas cost exceeds 100000") '''

Error Message: Traceback (most recent call last): File "D:\Accumulate\new_02_02\documentation_1.py", line 33, in compiled_sol = compile_source_file('contract.sol') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Accumulate\new_02_02\documentation_1.py", line 18, in compile_source_file return compile_source(source,output_values=['abi','bin']) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Accumulate\new_02_02\env\Lib\site-packages\solcx\main.py", line 101, in compile_source return _compile_combined_json( ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Accumulate\new_02_02\env\Lib\site-packages\solcx\main.py", line 257, in _compile_combined_json solc_binary = get_executable(version=solc_version) if solc_binary is None else solc_binary ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Accumulate\new_02_02\env\Lib\site-packages\solcx\install.py", line 186, in get_executable raise SolcNotInstalled( solcx.exceptions.SolcNotInstalled: Solc is not installed. Call solcx.get_installable_solc_versions() to view for available versions and solcx.install_solc() to install.

linear[bot] commented 7 months ago

APE-1665 Trouble with Solc Installation in Python: SolcNotInstalled Error

gontsharuk commented 1 week ago

I had to downgrade to version 1.1.1 to make this work. It's broken since version 2.0.0!