1

Im writing a simple python script to connect to a local bitcoin node and list transactions.

I created a virtual environment with:

virtualenv bitcoinenv

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:

python bitcoin.py

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:

which python

I get:

/Users/me/Bitcoin/exchange/bitcoinenv/bin/python

When I run:

echo $VIRTUAL_ENV

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:

enter image description here

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:

Python 3.8.0

Has anyone any idea why I cant import the python-bitcoinlib library?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.