ModuleNotFoundError: No module named 'bitcoin' Here's my code:

from bitcoin.rpc import RawProxy
# Create a connection to local Bitcoin Core node
p = RawProxy()
# Run the getinfo command, store the resulting data in info
info = p.getinfo()
# Retrieve the 'blocks' element from the info
print(info['blocks'])


I could execute the RPC using curl:

➜  bitcoin git:(master) curl --user glaksmono --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332
Enter host password for user 'glaksmono':
{"result":{"walletname":"wallet.dat","walletversion":159900,"balance":0.00000000,"unconfirmed_balance":0.00000000,"immature_balance":0.00000000,"txcount":0,"keypoololdest":1523932637,"keypoolsize":999,"keypoolsize_hd_internal":1000,"paytxfee":0.00000000,"hdmasterkeyid":"6e64f10c7c94532b597feaec70369df40ae84023"},"error":null,"id":"curltest"}


I've also installed python-bitcoinlib successfully:

➜  Sandbox pip install python-bitcoinlib
Collecting python-bitcoinlib
  Downloading https://files.pythonhosted.org/packages/30/03/fb7df95fe89baede202cf3fe65e65bea4bf863061b5e8f59b12dab538240/python_bitcoinlib-0.10.1-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.5MB/s
Installing collected packages: python-bitcoinlib


Ideas how should I execute the RPC through the Python code?



The result of my script and the python and pip versions are below:

➜  Sandbox pip --version
pip 10.0.0 from /Library/Python/2.7/site-packages/pip (python 2.7)
➜  Sandbox python --version
Python 3.6.4

➜  Sandbox python rpc_example.py
Traceback (most recent call last):
  File "rpc_example.py", line 1, in &lt;module&gt;
    from bitcoin.rpc import RawProxy
ModuleNotFoundError: No module named 'bitcoin'
You are using a version of pip with a different version of Python. You are using Python 3 but your pip is for Python 2. Thus anything that pip installs will not be available to your Python which is why it cannot find the correct library. You will need to do pip3 install python-bitcoinlib in order to install the library for your python version.