After install Scrapy via pip, and having Python 2.7.10
:
scrapyTraceback (most recent call last):File "/usr/local/bin/scrapy", line 7, infrom scrapy.cmdline import executeFile "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 48, in from scrapy.spiders import SpiderFile "/Library/Python/2.7/site-packages/scrapy/spiders/__init__.py", line 10, in from scrapy.http import RequestFile "/Library/Python/2.7/site-packages/scrapy/http/__init__.py", line 12, in from scrapy.http.request.rpc import XmlRpcRequestFile "/Library/Python/2.7/site-packages/scrapy/http/request/rpc.py", line 7, in from six.moves import xmlrpc_client as xmlrpclibImportError: cannot import name xmlrpc_client
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 in Python 2, and at in Python 3. Note that these are part of the standard library.
The mapping was added to ; 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 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 syssys.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.
解决方案:
sudo pip uninstall six
easy_install six