Bitcoin Forum
March 20, 2019, 02:39:32 PM *
News: Latest Bitcoin Core release: 0.17.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: python-bitcoinrpc: modulenotfounderror no module named 'bitcoinrpc'  (Read 74 times)
rajalaxmi
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
March 15, 2019, 09:03:55 AM
Merited by ETFbitcoin (1), LoyceV (1)
 #1

I'm running bitcoind/ bitcoind -regtest on Windows 10 and am already able to use bitcoin-cli -regtest along with json-rpc methods to perform basic operations and get balances etc. When I try to do this programmatically on python 3 using Jeff Garzik's python-bitcoinrpc package (https://github.com/jgarzik/python-bitcoinrpc) I get a modulenotfounderror. However, my pip3 freeze shows python-bitcoinlib==0.10.1 and also python-bitcoinrpc==1.0.

My code is below (18443 is the regtest port):
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException

rpc_connection = AuthServiceProxy("http://%s:%s@127.0.0.1:18443"%("myrpcuser", "myrpcpassword"))
best_block_hash = rpc_connection.getbestblockhash()
print(rpc_connection.getblock(best_block_hash))

What am I doing wrong?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
HCP
Legendary
*
Offline Offline

Activity: 910
Merit: 1261

<insert witty quote here>


View Profile
March 15, 2019, 09:53:17 AM
 #2

I'm running bitcoind/ bitcoind -regtest on Windows 10 and am already able to use bitcoin-cli -regtest along with json-rpc methods to perform basic operations and get balances etc. When I try to do this programmatically on python 3 using Jeff Garzik's python-bitcoinrpc package (https://github.com/jgarzik/python-bitcoinrpc)
 I get a modulenotfounderror. However, my pip3 freeze shows python-bitcoinlib==0.10.1 and also python-bitcoinrpc==1.0.
What am I doing wrong?

Well... according to the install instructions on github... it looks like this might be Python 2 only...
change the first line of setup.py to point to the directory of your installation of python 2.*

Have you tried it with a Python 2.7 install? Huh

rajalaxmi
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
March 15, 2019, 10:28:54 AM
 #3

Thank you for your reply. Afraid I haven't tried with python 2.7. I'm new to python and have spent quite a lot of time making stuff with python 3 so I would like to avoid moving to python 2 now. Would you happen to know any other way in which I can make the json-rpc calls to bitcoind from python 3? Appreciate your help.
bob123
Hero Member
*****
Offline Offline

Activity: 840
Merit: 834



View Profile WWW
March 15, 2019, 11:25:42 AM
 #4

Actually it should also work with python3.

Python can be quite cocky with the 'Module not found' errors.
You might have to adjust the path to get it working.

But syntactically there is not a lot of difference between python3 and python2. Those are just minimal.
If you are familiar with python3, you will easily be able to get your code working in python2.


Your only 2 options are to either get it working via adjusting paths / making changes to the package or using python2.

rajalaxmi
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
March 15, 2019, 11:58:54 AM
 #5

Thanksfor your reply! How/ where do I adjust the path, please? I installed the package directly using "pip3 install python-bitcoinrpc". And then I tried importing it from within my python script (I use spyder IDE). Sorry for the noob question but where should I be adjusting paths and what should the new path be, please?
ETFbitcoin
Legendary
*
Offline Offline

Activity: 1624
Merit: 1647

Use SegWit and enjoy lower fees.


View Profile WWW
March 15, 2019, 07:22:45 PM
Last edit: March 15, 2019, 07:36:54 PM by ETFbitcoin
 #6

Thanksfor your reply! How/ where do I adjust the path, please? I installed the package directly using "pip3 install python-bitcoinrpc". And then I tried importing it from within my python script (I use spyder IDE). Sorry for the noob question but where should I be adjusting paths and what should the new path be, please?

I tried what you did (install with pip and copy the code from 1st post) and it works properly, except i didn't set my RPC-JSON username/password. Tried with Python 3.7 on Debian Stretch.

Check this guide if you still face the problem https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path.
If you don't care about cross-OS usability, then use guide from Daryl Spitzer and find out default location of python module. On linux, it should be located somewhere near /usr/local/lib/python3.7/dist-packages/bitcoinrpc/

rajalaxmi
Newbie
*
Offline Offline

Activity: 5
Merit: 2


View Profile
March 16, 2019, 03:59:28 AM
 #7

Is there a video tutorial on Youtube/elsewhere on how to make json-rpc calls from python, or to use this python-bitcoinrpc library? The instructions are very sparse on the github page and I'm keen to learn this. I'm sure many people are as keen as I am, but I can't find any such video.
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!