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

Clarify solc unavailable message #40

Open
carver opened this issue Nov 29, 2017 · 9 comments
Open

Clarify solc unavailable message #40

carver opened this issue Nov 29, 2017 · 9 comments

Comments

@carver
Copy link
Contributor

carver commented Nov 29, 2017

What was wrong?

The error message is not clear, when solc isn't available.

Examples:

Proposal: catch and reraise the exception with a note saying something like:

The command line tool solc wasn't found. Try python -m solc.install v0.4.17 or see http://solidity.readthedocs.io/en/latest/installing-solidity.html

Cute Animal Picture

cute animal

@jasonrhaas
Copy link

jasonrhaas commented Dec 14, 2017

+1 for this. Just ran into this in trying to get the web3.py quickstart to run.

Even after install py-solc and doing python -m solc.install v0.4.17 I still get:

Traceback (most recent call last):
  File "quickstart.py", line 29, in <module>
    compiled_sol = compile_source(contract_source_code) # Compiled source code
  File "/usr/local/lib/python3.6/site-packages/solc/main.py", line 106, in compile_source
    stdoutdata, stderrdata, command, proc = solc_wrapper(**compiler_kwargs)
  File "/usr/local/lib/python3.6/site-packages/solc/utils/string.py", line 85, in inner
    return force_obj_to_text(fn(*args, **kwargs))
  File "/usr/local/lib/python3.6/site-packages/solc/wrapper.py", line 155, in solc_wrapper
    stderr=subprocess.PIPE)
  File "/usr/local/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'solc': 'solc'

@jasonrhaas
Copy link

Maybe adding a try/except here https://github.com/ethereum/py-solc/blob/master/solc/wrapper.py#L152-L155

is a good approach. Like:

try:
    proc = subprocess.Popen(command,
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE) 
except FileNotFoundError as e:
   raise FilenotFoundError("Added Error Message") from e

@pipermerriam
Copy link
Member

I think the right place to catch this is in in solc/wrapper.py#L53 and to use solc.utils.filesystem.is_executable_available to check that solc_binary is present. We can then raise a FileNotFound error with a friendly error message.

@jasonrhaas
Copy link

@pipermerriam cool, I think I can probably add that in as part of the work I'm doing on Web3.py. I ran into this as I was setting up a test bed for work on Web3.py. Still having an issue actually even though I installed Solidity. Must be a path or environment issue I'm guessing?

@pipermerriam
Copy link
Member

Yeah, if solc isn't on your $PATH you can either add it to your $PATH or set the environment variable SOLC_BINARY to the path to the solc executable.

step21 added a commit to step21/py-solc that referenced this issue Jan 28, 2018
start for ethereum#40 (still untested)
@grde1988
Copy link

grde1988 commented Feb 24, 2018

Hello Gentlemen,

Is there any clarity on this py-solc import issue? I have it installed but still not able to import the module into my python scripts:

https://ethereum.stackexchange.com/questions/26192/errno-2-no-such-file-or-directory-solc-using-py-solc-and-solidity/40768#40768

>>> import solc Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'solc'

Thank you for all the great work!

Ricardo

PS.

I attempted to add the path provided with which solc to my $PATH but not sure that is working/I'm doing it right. Thanks again.

@carver
Copy link
Contributor Author

carver commented Feb 26, 2018

@grde1988 that's a different issue (notice the difference between the errors: "No such file or directory" and "ImportError: No module named 'solc'"). Please ask a fresh stackexchange question, including your steps taken to set up, versions installed (using pip freeze), etc.

@AlexanderLife
Copy link

FileNotFoundError: [Errno 2] No such file or directory: 'solc': 'solc'

short:
solc != solcjs
type solcjs --help
type solc --help
see the problem
did you get bash: solc: command not found for solc --help
if so type sudo npm install -g solc-cli

long bs:
it's not finding solc

so for me when you do a fresh sudo npm install -g solc then when you type solc --help it says

bash: solc: command not found

but I installed it. oh wait when I type solcjs --help it works as expected guess we just had to guess 2 letters.

I do npm search solc hummm solc-cli I bet cLi stands for Command Line Interface if I was a compiler I say something like undeclared identifier. this is something important to remember in documenting your code people are compilers, define don't just show 1337 scripts you could do with the cool tool. sorry, I'm a little frustrated with JavaScript people and their relation to solidity compile and deployment. hopefully abstracting to python will solve my problems. just saying everything with compile and deployment should be handled as preprocessor directives in solidity completely remove all JS and replace it with a real compiler. you could do something like #GAS: 2000000; #PORT: 9545; #LINKLIBRARY:

;
I don't think it would really be that hard you could do something like python3 -m py-solc path/to/file.sol for compiling and deploying. oh how hypocritical of me I am not defining http://www.cplusplus.com/doc/tutorial/preprocessor/ , https://en.wikipedia.org/wiki/C_preprocessor.

anyway to fix this the above error we sudo npm install -g solc-cli after successful install we type solc --help it works as expected.

hopefully the error has now changed to a easy one!

so another issue I had was I had two pythons 2 and 3 on my system and pip wanted to only install on python 2 the fix to that was to run pip as module sudo python3 -m pip install py-solc I am not really that experienced with python so it was a little hard for me but maybe it will help someone.

@dylanjw
Copy link

dylanjw commented Mar 29, 2018

#48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants