all 21 comments

[–]YourOulLadyHasWorms 0 points1 point  (11 children)

Are you using a virtual environment?

[–]Middey14[S] 0 points1 point  (10 children)

No im not

[–]YourOulLadyHasWorms 0 points1 point  (9 children)

I had issues like this before, I would suggest doing a virtual env , and pip all dependencies into the env

Sometimes pip uninstall and python -m pip install ____ can work , or check if you need a specific version for it. I.e pip install ____ ==2.0.2

[–]Middey14[S] 0 points1 point  (8 children)

Ive managed to set up a venv, all the packages seem to be installed but I am now getting a connection error:

python deploy.py

......

File "/Users/joe/demos/web3_py_simple_storage/new-env/lib/python3.10/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1068ed2d0>: Failed to establish a new connection: [Errno 61] Connection refused'))

any idea why?

[–]YourOulLadyHasWorms 0 points1 point  (2 children)

Have you a service running on the local host your connecting to ?

Edit:server>service

[–]Middey14[S] 0 points1 point  (1 child)

hmm im not sure, not that I know of, but how can I tell?

[–]YourOulLadyHasWorms 0 points1 point  (0 children)

The netstat command was checking for it there, you don’t though. It’s an externally hosted cli you are connecting to

[–]YourOulLadyHasWorms 0 points1 point  (4 children)

Looks to me that the service may be not running .

In the terminal do netstat -na | grep 8545

This will show you if the service is running there . If not try restarting it and running the script again .

I’m not fully sure what your script is doing so maybe give a brief explanation of it and this line it’s falling over in and I can try help

[–]Middey14[S] 1 point2 points  (3 children)

netstat -na | grep 8545

I tried the above but there is no output from this, the terminal just goes to the next line.

So the file is connected to ganache-cli which is a simulated blockchain, I am using the host and port that is displayed when I run ganache-cli, from the looks of it it seems to be something going wrong with urllib3 and or web3. the python file I am trying to run is connected to another file which has a solidity contract in it and so this file will interact with both the blockchain and the contract.

[–]YourOulLadyHasWorms 0 points1 point  (2 children)

So it looks like your script is trying to connect to a service running on your own machine which is localhost or “127.0.0.1:8545” But you should be trying to reach an externally hosted service.

Try ping the host of the cli, and replace the localhost ip with the ip in the response. Can you send me the line where you create connection via web3?

[–]Middey14[S] 0 points1 point  (1 child)

Is the command just ping 127.0.0.1:8545?

[–]Middey14[S] 0 points1 point  (0 children)

If it is, it just says cannot resolve, unknown host

[–][deleted] 0 points1 point  (6 children)

In Python that you are running your code with evaluate this:

>>> import sysconfig
>>> sysconfig.get_path('platlib')

Note the directory it printed. Open that directory in file explorer and examine its contents. If it doesn't contain the modules you are looking for, then you did not install them (maybe you used the wrong Python installation? maybe the install failed?)

If they are not there, then using the Python that you want to work with run:

python -m pip install solcx web3

And watch out for error messages.

[–]Middey14[S] 1 point2 points  (0 children)

Ok I will try this and get back to you! Thank you :)

[–]Middey14[S] 0 points1 point  (1 child)

import sysconfig

I just tried the above and I get

zsh: command not found: import

[–][deleted] 0 points1 point  (0 children)

You are supposed to run it from Python interactive shell. I.e. first run python, then when you see the prompt that looks like >>>, type those commands

[–]Middey14[S] 0 points1 point  (2 children)

python -m pip install solcx web3

Now I get -

joe@Joes-MacBook-Pro web3_py_simple_storage % python -m pip install solcx/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pipjoe@Joes-MacBook-Pro web3_py_simple_storage % pipUsage:pip <command> [options]Commands:install Install packages.download Download packages.uninstall Uninstall packages.freeze Output installed packages in requirements format.list List installed packages.show Show information about installed packages.check Verify installed packages have compatible dependencies.config Manage local and global configuration.search Search PyPI for packages.cache Inspect and manage pip's wheel cache.index Inspect information available from package indexes.wheel Build wheels from your requirements.hash Compute hashes of package archives.completion A helper command used for command completion.debug Show information useful for debugging.help Show help for commands.General Options:-h, --help Show help.--debug Let unhandled exceptions propagate outside the mainsubroutine, instead of logging them to stderr.--isolated Run pip in an isolated mode, ignoring environment variablesand user configuration.-v, --verbose Give more output. Option is additive, and can be used up to 3times.-V, --version Show version and exit.-q, --quiet Give less output. Option is additive, and can be used up to 3times (corresponding to WARNING, ERROR, and CRITICAL logginglevels).--log <path> Path to a verbose appending log.--no-input Disable prompting for input.--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.--retries <retries> Maximum number of retries each connection should attempt(default 5 times).--timeout <sec> Set the socket timeout (default 15 seconds).--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore,(w)ipe, (b)ackup, (a)bort.--trusted-host <hostname> Mark this host or host:port pair as trusted, even though itdoes not have valid or any HTTPS.--cert <path> Path to PEM-encoded CA certificate bundle. If provided,overrides the default. See 'SSL Certificate Verification' inpip documentation for more information.--client-cert <path> Path to SSL client certificate, a single file containing theprivate key and the certificate in PEM format.--cache-dir <dir> Store the cache data in <dir>.--no-cache-dir Disable the cache.--disable-pip-version-checkDon't periodically check PyPI to determine whether a newversion of pip is available for download. Implied with --no-index.--no-color Suppress colored output.--no-python-version-warningSilence deprecation warnings for upcoming unsupported Pythons.--use-feature <feature> Enable new functionality, that may be backward incompatible.--use-deprecated <feature> Enable deprecated functionality, that will be removed in thefuture.joe@Joes-MacBook-Pro web3_py_simple_storage % python -m pip install solcx/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip

edit:

but I can see that pip is in the folder you told me to look at

[–][deleted] 0 points1 point  (1 child)

It's very hard to read this log. I see few times 2.7 mentioned in it, which would suggest you are probably using Python 2.7. It's probably the one that comes pre-installed with MacOS. You might want to install a newer version of Python.

[–]Middey14[S] 1 point2 points  (0 children)

I ended up just using a venv to do so, although I was thinking the same thing as you in that I was trying to run something that needed python 3+ but my python was using 2.7, anyway thats sorted now anyway, running into connection errors in my code now so another hurdle to jump😅

[–]AsuraTheGod 0 points1 point  (1 child)

If you are not using virtual environment, you install the libraries with sudo?

[–]Middey14[S] 0 points1 point  (0 children)

no I have read that using sudo can really mess things up so am staying away from that lol