I'm copying some code snippet from openstack, but when it runs to:
import six.moves.xmlrpc_client as xmlrpclib
I got the following error:
import six.moves.xmlrpc_client as xmlrpclib
ImportError: No module named xmlrpc_client
I have install the six package. How to solve this problem?
I'm working on MacOS with python 2.7.
I tried to install but failed:
lichaos-MacBook-Pro:common lichao$ sudo pip install --allow-unverified xmlrpclib xmlrpclib
Collecting xmlrpclib
xmlrpclib is potentially insecure and unverifiable.
Downloading http://effbot.org/media/downloads/xmlrpclib-1.0.1.zip
Installing collected packages: xmlrpclib
Running setup.py install for xmlrpclib
changing mode of build/scripts-2.7/xmlrpc_handler.py from 644 to 755
changing mode of build/scripts-2.7/xmlrpcserver.py from 644 to 755
changing mode of build/scripts-2.7/echotest.py from 644 to 755
changing mode of /usr/local/bin/echotest.py to 755
changing mode of /usr/local/bin/xmlrpc_handler.py to 755
changing mode of /usr/local/bin/xmlrpcserver.py to 755
Successfully installed xmlrpclib-1.0.1
$ sudo pip show six
---
Name: six
Version: 1.8.0
Location: /Library/Python/2.7/site-packages
Requires:
But when I run my program, I still got same error. How to solve the problem?
six.moves is a virtual namespace. It provides access to packages that were renamed between Python 2 and 3. As such, you shouldn't be installing anything.
By importing from six.moves.xmlrpc_client the developer doesn't have to handle the case where it is located at xmlrpclib in Python 2, and at xmlrpc.client in Python 3. Note that these are part of the standard library.
The mapping was added to six version 1.5.0; make sure you have that version or newer.
Mac comes with six version 1.4.1 pre-installed in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python and this will interfere with any version you install in site-packages (which is listed last in the sys.path).
The best work-around is to use a virtualenv and install your own version of six into that, together with whatever else you need for this project. Create a new virtualenv for new projects.
If you absolutely have to install this at the system level, then for this specific project you'll have to remove the /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python path:
import sys
sys.path.remove('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
This will remove various OS X-provided packages from your path for just that run of Python; Apple installs these for their own needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With