简体   繁体   English

Scrapy抛出ImportError:无法导入名称xmlrpc_client

[英]Scrapy throws ImportError: cannot import name xmlrpc_client

After install Scrapy via pip, and having Python 2.7.10 : 通过pip安装Scrapy之后,并安装了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

But I can import module: 但是我可以导入模块:

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

What's going on? 这是怎么回事?

I've just fixed this issue on my OS X. 我刚刚在OS X上解决了这个问题。

Please backup your files first. 请先备份您的文件。

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 is ready to go. Scrapy 1.0.0已准备就绪。


If you encounter an error rm: /System/Library/... Operation not permitted 如果遇到错误rm: /System/Library/... Operation not permitted

Please try to disable System Integrity Protection 请尝试禁用系统完整性保护
See Operation Not Permitted when on root El capitan (rootless disabled) 请参阅在根El capitan上不允许的操作(禁用无根)

This is a known issue on Mac OSX for Scrapy. 这是Mac OSX上Scrapy的一个已知问题。 You can refer to this link . 您可以参考此链接

Basically the issue is with the PYTHONPATH in your system. 基本上,问题出在系统中的PYTHONPATH。 To solve the issue change the current PYTHONPATH to point to the newer or none Mac OSX version of Python. 要解决此问题,请将当前的PYTHONPATH更改为指向Mac OSX的更新版本或没有指向Python的版本。 Before running Scrapy, try: 在运行Scrapy之前,请尝试:

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

If that worked you can change the .bashrc file permanently: 如果可行,您可以永久更改.bashrc文件:

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

If none of this works, take a look at the link above. 如果这些都不起作用,请查看上面的链接。

I had the same exact problem when upgrading to Scrapy 1.0. 升级到Scrapy 1.0时,我遇到了同样的问题。 After numerous work arounds the solution that worked for me was uninstalling six with pip: 经过大量的工作后,对我有用的解决方案是使用pip卸载六个:

sudo pip uninstall six sudo pip卸载六

then re-installing six via easy_install 然后通过easy_install重新安装六个

easy_install six easy_install六

Hope that works! 希望有效!

Better than downgrading Scrapy it's to upgrade your version of six: 比降级Scrapy更好的是升级六个版本:

pip install --upgrade six scrapy

This will allow you to use all the goodies from Scrapy 1.0 ;) 这将允许您使用Scrapy 1.0中的所有功能;)

I just had the same issue. 我只是有同样的问题。 Try this: 尝试这个:

sudo pip uninstall scrapy sudo pip卸载scrapy

sudo pip install scrapy==0.24.2 sudo pip install scrapy == 0.24.2

Then give it a shot 然后试一试

I believe the best solution on OS X should be "Don't use system python". 我相信OS X上最好的解决方案应该是“不要使用系统python”。 It will make life easier. 这将使生活更轻松。 This link shows how to do this. 此链接显示了如何执行此操作。

There's a known issue that prevents pip from updating system packages. 有一个已知的问题,阻止pip更新系统软件包。 This has to be addressed to successfully install Scrapy and its dependencies. 必须解决此问题才能成功安装Scrapy及其依赖项。 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. (推荐)不要使用系统python,安装新的更新版本,该版本应与系统的其余部分不冲突。 Here's how to do it using the homebrew package manager: 使用自制程序包管理器的方法如下:

  1. Install homebrew following the instructions in http://brew.sh/ 按照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): 更新您的PATH变量,以指出应在系统软件包之前使用自制软件包(如果将zsh用作默认外壳,则将.bashrc更改为.zshrc):

echo "export PATH=/usr/local/bin:/usr/local/sbin:$PATH" >> ~/.bashrc 回声“导出路径= / usr / local / bin:/ usr / local / sbin:$ PATH” >>〜/ .bashrc

  1. Reload .bashrc to ensure the changes have taken place: 重新加载.bashrc以确保已进行更改:

source ~/.bashrc 来源〜/ .bashrc

  1. Install python: 安装python:

brew install python brew安装python

  1. Latest versions of python have pip bundled with them so you won't need to install it separately. 最新版本的python已捆绑了pip,因此您无需单独安装。 If this is not the case, upgrade python: 如果不是这种情况,请升级python:

brew update; 酿造更新; brew upgrade python 酿造升级python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM