Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with Solc Installation in Python: SolcNotInstalled Error #166

Open
abhishek165 opened this issue Feb 2, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@abhishek165
Copy link

Environment information

  • py-solc-x Version: 0.6.0
  • solc Version: 0.8.23
  • Python Version: 3.11
  • OS: win

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.

@abhishek165 abhishek165 added the bug Something isn't working label Feb 2, 2024
Copy link

linear bot commented Feb 2, 2024

@gontsharuk
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants