After install Scrapy via pip, and having Python 2.7.10
:
scrapy Traceback (most recent call last): File "/usr/local/bin/scrapy", line 7, in <module> from scrapy.cmdline import execute File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 48, in <module> from scrapy.spiders import Spider File "/Library/Python/2.7/site-packages/scrapy/spiders/__init__.py", line 10, in <module> from scrapy.http import Request File "/Library/Python/2.7/site-packages/scrapy/http/__init__.py", line 12, in <module> from scrapy.http.request.rpc import XmlRpcRequest File "/Library/Python/2.7/site-packages/scrapy/http/request/rpc.py", line 7, in <module> from six.moves import xmlrpc_client as xmlrpclib ImportError: 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 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.
解决方案:
sudo pip uninstall six
easy_install six