关于python:scrapy throws importError:无法导入名称xmlrpc_client

Scrapy throws ImportError: cannot import name xmlrpc_client

通过PIP安装废料后,有Python 2.7.10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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

但我可以导入模块:

1
2
3
4
5
Python 2.7.10 (default, Jun 10 2015, 19:42:47)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type"help","copyright","credits" or"license" for more information.
>>> import scrapy
>>>

发生什么事?


我刚在我的OS X上解决了这个问题。

请先备份文件。

1
2
3
sudo rm -rf /Library/Python/2.7/site-packages/six*
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six*
sudo pip install six

Scrapy1.0.0准备好了。

如果遇到错误rm: /System/Library/... Operation not permitted

请尝试禁用系统完整性保护请参阅在根el capitan上不允许的操作(禁用无根)


这是MacOSX上关于Scrapy的一个已知问题。你可以参考这个链接。

基本上,问题在于你的系统中的Python路径。要解决此问题,请将当前pythonpath更改为指向更新或无mac osx版本的python。在运行Scrapy之前,请尝试:

export PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH

如果成功,您可以永久更改.bashrc文件:

echo"export PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH">> ~/.bashrc

如果这些都不起作用,请查看上面的链接。


我升级到Scrapy1.0时也遇到了同样的问题。经过无数次的工作之后,我的解决方案是用pip卸载六个:

sudo pip uninstall six

然后通过轻松安装重新安装6个

easy_install six

希望能成功!


比降级报废更好的是升级你的版本6:

1
pip install --upgrade six scrapy

这将允许您使用Scrapy 1.0;提供的所有商品)


我也有同样的问题。试试这个:

sudo pip卸载scrapy

sudo pip安装碎屑y==0.24.2

那就试试看


我认为OSX上最好的解决方案应该是"不要使用系统python"。它会让生活更轻松。此链接显示如何执行此操作。

There’s a known issue that prevents pip from updating system packages. This has to be addressed to successfully install Scrapy and its dependencies. Here are some proposed solutions:

(Recommended) Don’t use system python, install a new, updated version that doesn’t conflict with the rest of your system. Here’s how to do it using the homebrew package manager:

  • Install homebrew following the instructions in http://brew.sh/
  • Update your PATH variable to state that homebrew packages should be used before system packages (Change .bashrc to .zshrc accordantly if you’re using zsh as default shell):
  • echo"export PATH=/usr/local/bin:/usr/local/sbin:$PATH">> ~/.bashrc

  • Reload .bashrc to ensure the changes have taken place:
  • source ~/.bashrc

  • Install python:
  • brew install python

  • Latest versions of python have pip bundled with them so you won’t need to install it separately. If this is not the case, upgrade python:
  • brew update; brew upgrade python