[Ethereum] Cannot import Web3 from web3

web3.py

I've repeatedly installed web3 via pip on an ubuntu OS (17.04, running on a DigitalOcean droplet) but for some reason when I attempt to run "from web3 import Web3" I get this response:

ModuleNotFoundError: No module named 'web3'

I think it has to do with pip because I've had trouble installing other modules (eth-testrpc). Any advice?

Best Answer

From the terminal, install Web3.py using pip with the following command:

pip install web3

To use the web3 library you will need to instantiate a Web3 object:

>>> from web3 import Web3, HTTPProvider, IPCProvider
>>> web3 = Web3(HTTPProvider('http://localhost:8545'))

>>> web3.eth.blockNumber
4000000

or for an IPC based connection

>>> web3 = Web3(IPCProvider())

Note that you should create only one RPCProvider per process, as it recycles underlying TCP/IP network connections between your process and Ethereum node.