Web3.py: Cannot import web3

Created on 3 Apr 2018  路  6Comments  路  Source: ethereum/web3.py

  • pip 9.0.3
  • Python: 3.5
  • OS: linux (ubuntu)
### pip install:
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv
#once
$ virtualenv -p python3 ~/.venv-py3
# each session:
$ source ~/.venv-py3/bin/activate

Current session is: (.venv-py3) user$

When I use following line on my python file:
from web3.auto import w3

I receive the following error:

Traceback (most recent call last):
  File "getClusterAddresses.py", line 5, in <module>
    from web3.auto import w3
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/web3/__init__.py", line 7, in <module>
    from eth_account import Account  # noqa: E402
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_account/__init__.py", line 1, in <module>
    from eth_account.account import Account  # noqa: F401
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_account/account.py", line 10, in <module>
    from eth_keyfile import (
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_keyfile/__init__.py", line 7, in <module>
    from eth_keyfile.keyfile import (  # noqa: F401
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_keyfile/keyfile.py", line 10, in <module>
    from eth_keys import keys
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_keys/__init__.py", line 15, in <module>
    from .main import (  # noqa: F401
  File "/home/alper/.venv-py3/lib/python3.5/site-packages/eth_keys/main.py", line 1, in <module>
    from typing import (Any, Union, Type)  # noqa: F401
ImportError: cannot import name 'Type'

Most helpful comment

There is a backport of the typing library you can use if needed: https://pypi.python.org/pypi/typing

All 6 comments

What's the result of python --version while in the virtualenv?

typing.Type was introduced in version 3.5.2 according to https://docs.python.org/3/library/typing.html

(.venv-py3) $ python --version
Python 3.5.0

=> Is this correct way to import web3 library: from web3.auto import w3?
=> Do I need to upgrade to 3.5.2? (I couldn't find a way to upgrade it to 3.5.2 ) @carver

Is this correct way to import web3 library: from web3.auto import w3?

Yup, as long as your node is running at one of a few common locations. Check http://web3py.readthedocs.io/en/stable/providers.html#automatic-provider-detection

Do I need to upgrade to 3.5.2? (I couldn't find a way to upgrade it to 3.5.2 )

Yes

There is a backport of the typing library you can use if needed: https://pypi.python.org/pypi/typing

I'm on python 3.7 and I am getting this error.

@redserpent7 please open a new ticket, with the full traceback, the result of python -V, and your installed libraries (pip list).

Was this page helpful?
0 / 5 - 0 ratings