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?

Michael Folkson
  • 14,337
  • 3
  • 11
  • 45
Mark
  • 137
  • 3

0 Answers0