2015-06-21 14 views
33

Dopo l'installazione Scrapy via pip, e avendo Python 2.7.10:Scrapy getta ImportError: non si può importare nome 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 

Ma posso importare il modulo:

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

Cosa sta succedendo?

+0

Hai provato a disinstallare e reinstallare 'sei'? –

risposta

71

Ho appena risolto questo problema sul mio OS X.

Prima di eseguire il backup dei file.

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 è pronto ad andare.


Se si verifica un errore rm: /System/Library/... Operation not permitted

prega di provare a disabilitare System Integrity Protection
Vedi Operation Not Permitted when on root El capitan (rootless disabled)

+0

È accaduto anche qui. Sembra esclusivo di OS X – danielmhanover

+0

Ha funzionato bene per me. – sahara108

+4

Questo mi ha aiutato. Ho disinstallato scrapy. Eseguito i comandi sopra, quindi installato scrapy 1.0.0: 'sudo pip installa scrapy == 1.0.0'. Grazie :) – thedp

3

Ho appena avuto lo stesso problema. Prova questo:

sudo disinstallazione pip Scrapy

sudo pip install Scrapy == 0.24.2

poi dare un colpo

+1

hm, è meglio aggiornare sei rispetto all'utilizzo di Scrapy precedente. 'pip install --upgrade six' dovrebbe farlo. – elias

+0

Il downgrade del pacchetto non risolve il problema. Ottiene un vecchio pacchetto che è stato aggiornato per un motivo ... –

5

Meglio di declassamento Scrapy è aggiornare la versione di sei:

pip install --upgrade six scrapy 

Questo ti permetterà di usare tutti i gadget di Scrapy 1.0;)

+0

@downvoter: cura di commentare? – elias

32

Questo è un problema noto su Mac OSX per Scrapy. È possibile fare riferimento a this link.

Fondamentalmente il problema riguarda il sistema PYTHONPATH. Per risolvere il problema cambia l'attuale PYTHONPATH in modo che punti alla versione Mac OSX più recente o nessuna di Python. Prima di eseguire Scrapy, provare:

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

Se che ha funzionato è possibile modificare il file .bashrc in modo permanente:

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

Se tutto questo non funziona, date un'occhiata al link qui sopra.

+0

Sembra che funzioni per me, grazie :) – SearchDream

18

Ho avuto lo stesso esatto problema durante l'aggiornamento a Scrapy 1.0. Dopo numerose arounds di lavoro la soluzione che ha funzionato per me è stata la disinstallazione sei con pip:

sudo pip uninstall six

quindi reinstallare sei tramite easy_install

easy_install six

Speranza che funziona!

+0

Questa è di gran lunga la soluzione più semplice. –

+1

L'uso di easy_install è [scoraggiato oggigiorno] (http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install). L'aggiornamento con pip è migliore. – elias

1

Credo che la migliore soluzione su OS X dovrebbe essere "Non usare python di sistema". Renderà la vita più facile. This link mostra come farlo.

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

Problemi correlati