7

I am working through Master Bitcoin. I got the bitcoin client up and running. I am now trying to access the client from python. In the example, there is a line that says from bitcoin.rpc import Rawproxy.

I get the error message no module named rpc. When I run pip freeze, I have python-bitcoinrpc==1.0 listed. Why can't this module be found?

user2242044
  • 207
  • 2
  • 6

3 Answers3

7

in debian =)

sudo apt-get install libssl-dev

pip install python-bitcoinlib or pip3 install python-bitcoinlib

  • Thank you. That worked. Can I ask how you knew this? there seems to be no association to the library name in `import` and what you install. I looked everywhere online trying to figure out the library. – user2242044 Sep 25 '17 at 19:57
0

First, install libssl-dev:

sudo apt-get install libssl-dev

Install python3-pip if not yet:

sudo apt install python3-pip

Lastly, install python-bitcoinlib:

pip3 install python-bitcoinlib

In the example code, it is

info = p.getinfo()

Ran the example, I got "bitcoin.rpc.JSONRPCError: {'code': -32601, 'message': 'Method not found'}"

Change it to:

info = p.getblockchaininfo()

(see https://bitcoincore.org/en/doc/0.21.0/rpc/blockchain/getblockchaininfo/)

It works fine. I got the total number of blocks. In my case, it is 682903.

Yong Yu
  • 1
  • 1
0

bicoinlib is the module you try to use to handle bitcoind, bitcoin-cli in python, rpc module is part of bitcoinlib.

libssl-dev is needed to handle SSL and TLS cryptographic protocols .

if bitcoinlib not work in newer bitcoin core versions 0.15 or newer just use raw bitcoinrpc.authProxy module.