<p>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 <code>pip3 install python-bitcoinlib</code> in order to install the library for your python version.</p>

CC BY-SA 4.0
2021-10-04T00:40:24.153Z
Shouldn't we use python 2?
Rony Tesler
CC BY-SA 3.0
2018-04-18T15:19:28.583Z
2018-04-18T15:27:23.587Z
2018-04-18T15:27:23.587Z
Ava Chow
<p>Here's my code:</p>

<pre><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'])
</code></pre>

<p>I could execute the RPC using <code>curl</code>:</p>

<pre><code>➜  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"}
</code></pre>

<p>I've also installed <code>python-bitcoinlib</code> successfully:</p>

<pre><code>➜  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
</code></pre>

<p>Ideas how should I execute the RPC through the Python code?</p>

<hr>

<p>The result of my script and the python and pip versions are below:</p>

<pre><code>➜  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'
</code></pre>

CC BY-SA 3.0
2018-04-18T15:21:29.160Z
How are you running the script? Can you post the full output of it? Can you also post the output of `python --version` and `pip --version`?
Ava Chow
CC BY-SA 3.0
2018-04-18T15:23:47.827Z
@AndrewChow here's what I'm getting: https://gist.github.com/glaksmono/df45548521901b89c5fc662c2a837e03
0xgoku
<bitcoin-core><bitcoind><python>
ModuleNotFoundError: No module named 'bitcoin'
0xgoku
# ModuleNotFoundError: No module named 'bitcoin'

(Asked by: username_0 on 2018-04-18)

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 <module>
    from bitcoin.rpc import RawProxy
ModuleNotFoundError: No module named 'bitcoin'

```

**Tags:** bitcoin-core, bitcoind, python

> **Comments:**
> **username_1**: How are you running the script? Can you post the full output of it? Can you also post the output of `python --version` and `pip --version`?  
> **username_0**: @AndrewChow here's what I'm getting: https://gist.github.com/glaksmono/df45548521901b89c5fc662c2a837e03  

---

## 1 answers

### Answer by username_1 on 2018-04-18. Score: 2

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.

> **Comments:**
> **username_2**: Shouldn't we use python 2?  

---

