No module name 'xmlrpclib' when using Electrum from Command line

Benji Weiss picture Benji Weiss · May 3, 2017 · Viewed 11.7k times · Source

I just installed a bitcoin wallet from command line from Electrum.org

heres how i installed it in my user account directory .. /home/user/...

sudo pip3 install https://download.electrum.org/2.8.2/Electrum-2.8.2.tar.gz

and it installed with no issues.

When i attempt to run the software from command line using electrum or if i try electrum help i get this ImportError

(heres their documentation http://docs.electrum.org/en/latest/cmdline.html)

ImportError: No module named 'xmlrpclib'

heres the traceback if you are trying to replicate it

File "/usr/local/bin/electrum", line 71, in check_imports
import jsonrpclib

File "/usr/local/lib/python3.5/dist-packages/jsonrpclib/__init__.py", line 5, in <module>
from jsonrpclib.jsonrpc import Server, MultiCall, Fault

File "/usr/local/lib/python3.5/dist-packages/jsonrpclib/jsonrpc.py", line 50, in <module> 
from xmlrpclib import Transport as XMLTrasnport

I have done

sudo apt-get update

sudo apt-get upgrade

sudo pip install xmlrpclib

but have had no avail.

If anyone can provide some insight thatd be greatly appreciated.

Answer

McGrady picture McGrady · May 3, 2017

The xmlrpclib module has been renamed to xmlrpc.client in Python 3.

So, if you want to use xmlrpclib

import xmlrpclib

Replace that with this:

from xmlrpc import client

This project has not been updated for two years, so you can find this file /usr/local/lib/python3.5/dist-packages/jsonrpclib/jsonrpc.py and change

from xmlrpclib import Transport as XMLTransport
from xmlrpclib import SafeTransport as XMLSafeTransport
from xmlrpclib import ServerProxy as XMLServerProxy
from xmlrpclib import _Method as XML_Method

to

from xmlrpc.client import Transport as XMLTransport
from xmlrpc.client import SafeTransport as XMLSafeTransport
from xmlrpc.client import ServerProxy as XMLServerProxy
from xmlrpc.client import _Method as XML_Method 

Also you can use 2to3 to convert the source:

2to3 -w jsonrpc.py

Then change

line 168 from http.client import HTTP, HTTPConnection
line 186     class UnixHTTP(HTTP):

To

line 168 from http.client import HTTPConnection
line 186     class UnixHTTP(HTTPConnection):

Hope this helps.