ModuleNotFoundError: Kein Modul mit dem Namen „bitcoin“

Hier ist mein Code:

from bitcoin.rpc import RawProxy
# Create a connection to local Bitcoin Core node
p = RawProxy()
# Run the getinfo command, store the resulting data in info
info = p.getinfo()
# Retrieve the 'blocks' element from the info
print(info['blocks'])

Ich könnte den RPC ausführen mit curl:

➜  bitcoin git:(master) curl --user glaksmono --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getwalletinfo", "params": [] }' -H 'content-type: text/plain;' http://127.0.0.1:18332
Enter host password for user 'glaksmono':
{"result":{"walletname":"wallet.dat","walletversion":159900,"balance":0.00000000,"unconfirmed_balance":0.00000000,"immature_balance":0.00000000,"txcount":0,"keypoololdest":1523932637,"keypoolsize":999,"keypoolsize_hd_internal":1000,"paytxfee":0.00000000,"hdmasterkeyid":"6e64f10c7c94532b597feaec70369df40ae84023"},"error":null,"id":"curltest"}

Ich habe auch python-bitcoinliberfolgreich installiert:

➜  Sandbox pip install python-bitcoinlib
Collecting python-bitcoinlib
  Downloading https://files.pythonhosted.org/packages/30/03/fb7df95fe89baede202cf3fe65e65bea4bf863061b5e8f59b12dab538240/python_bitcoinlib-0.10.1-py2.py3-none-any.whl (88kB)
    100% |████████████████████████████████| 92kB 1.5MB/s
Installing collected packages: python-bitcoinlib

Ideen, wie ich den RPC über den Python-Code ausführen soll?


Das Ergebnis meines Skripts und der Python- und Pip-Versionen sind unten:

➜  Sandbox pip --version
pip 10.0.0 from /Library/Python/2.7/site-packages/pip (python 2.7)
➜  Sandbox python --version
Python 3.6.4

➜  Sandbox python rpc_example.py
Traceback (most recent call last):
  File "rpc_example.py", line 1, in <module>
    from bitcoin.rpc import RawProxy
ModuleNotFoundError: No module named 'bitcoin'
Wie führen Sie das Skript aus? Kannst du die komplette Ausgabe davon posten? Kannst du auch die Ausgabe von python --versionund posten pip --version?
@AndrewChow hier ist, was ich bekomme: gist.github.com/glaksmono/df45548521901b89c5fc662c2a837e03

Antworten (1)

Sie verwenden eine Pip-Version mit einer anderen Python-Version. Sie verwenden Python 3, aber Ihr Pip ist für Python 2. Daher ist alles, was Pip installiert, für Ihr Python nicht verfügbar, weshalb es die richtige Bibliothek nicht finden kann. Sie müssen dies tun pip3 install python-bitcoinlib, um die Bibliothek für Ihre Python-Version zu installieren.

Sollten wir nicht Python 2 verwenden?