2015-06-21 184 views
33

通过PIP安装Scrapy后,并具有Python 2.7.10Scrapy抛出导入错误:无法导入名称xmlrpc_client

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 

但我可以导入模块:

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 
>>> 

这是怎么回事?

+0

你试过卸载并重新安装'six'吗? –

回答

71

我只是固定在我的OS X.

这个问题

请先备份您的文件。

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 

Scrapy 1.0.0已准备就绪。


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

请尝试禁用System Integrity Protection
看到比降级Scrapy更好Operation Not Permitted when on root El capitan (rootless disabled)

+0

这里也发生过这种情况。似乎是OS X专用的 – danielmhanover

+0

它对我来说很好。 – sahara108

+4

这帮了我。我已经卸载scrapy。执行上述命令,然后安装scrapy 1.0.0:'sudo pip install scrapy == 1.0.0'。谢谢:) – thedp

3

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

须藤PIP卸载scrapy

须藤PIP安装scrapy == 0.24.2

然后给它一个镜头

+1

hm,最好升级六个比使用旧的Scrapy。 'pip install --upgrade six'应该这样做。 – elias

+0

降级软件包不能解决问题。它得到了一个旧包,这是因为某种原因而升级的... –

5

它来升级你的六个版本:

pip install --upgrade six scrapy 

这将允许您使用Scrapy 1.0中的所有好东西; )

+0

@downvoter:照顾评论? – elias

32

这是Scrapy Mac OSX上的一个已知问题。你可以参考this link

基本上问题是在您的系统中的PYTHONPATH。要解决该问题,请将当前的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

如果没有这个工程,看看上面的链接。

+0

似乎这对我有用,谢谢:) – SearchDream

18

升级到Scrapy 1.0时,我遇到了同样的问题。许多变通后,对我工作的溶液卸载6与PIP:

sudo pip uninstall six

然后通过easy_install的

easy_install six

希望的作品重新安装6!

+0

这是迄今为止最简单的解决方案。 –

+1

使用easy_install [现在不鼓励](http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install)。 用pip升级更好。 – elias

1

我相信OS X上的最佳解决方案应该是“不要使用系统python”。它会让生活更轻松。 This link显示如何做到这一点。

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:

  1. Install homebrew following the instructions in http://brew.sh/
  2. 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

  1. Reload .bashrc to ensure the changes have taken place:

source ~/.bashrc

  1. Install python:

brew install python

  1. 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

相关问题