Hi
Im writing a simple python script to connect to a local bitcoin node and list transactions but I cant get the thing working.
I created a virtual environment with:
And then activated:
source bitcoinenv/bin/activate
The I installed python-bitcoinlib with:
pip install python-bitcoinlib
I have a simple script:
import requests
import bitcoin.rpc
# Connect to the local Bitcoin node
connection = bitcoin.rpc.Proxy()
# Get a list of unspent transactions
unspent_transactions = connection.listunspent()
# Print the unspent transactions
print(unspent_transactions)
And I run this with:
But I get the error:
import bitcoin.rpc
ModuleNotFoundError: No module named 'bitcoin.rpc'; 'bitcoin' is not a package
Heres more information about my environment. When I run:
I get:
/Users/me/Bitcoin/exchange/bitcoinenv/bin/python
When I run:
I get:
/Users/me/Bitcoin/exchange/bitcoinenv
When I go to `/Users/me/Bitcoin/exchange/bitcoinenv/lib/python3.8/site-packages` and list the contents I see python_bitcoinlib-0.11.2.dist-info amongst others listed (which I think is correct).
When I run `pip --version` I get:
pip 22.3.1 from /Users/me/Bitcoin/exchange/bitcoinenv/lib/python3.8/site-packages/pip (python 3.8)
And when I run `python --version` I get:
Has anyone any idea why I cant import the python-bitcoinlib library?
Thanks
EDIT:
I have changed the script to:
import bitcoin
from bitcoin.rpc import Proxy
# create a connection to the local bitcoin node
conn = Proxy(
network='regtest' # specify the network parameters as 'regtest'
)
# list the transactions in the wallet
print(conn.listtransactions())
When I run with
I see the error:
from bitcoin.rpc import Proxy
ModuleNotFoundError: No module named 'bitcoin.rpc'
This is VERY frustrating! Any ideas?