2015-11-26 14 views
8

Próbuję użyć Scrapy na Mac OS X El Capitan. Mam zainstalowany zsh i próbowałem wszystkiego, co mogłem znaleźć online, aby rozwiązać ten problem. Przyjrzałem się także Scrapy throws ImportError: cannot import name xmlrpc_client i nie mogłem rozwiązać mojego problemu! zainstalowanyMac OS X El Capitan - Scrapy/Python ImportError: nie można zaimportować nazwy xmlrpc_client

Python poprzez brew i dodał "pip zainstalować scrapy":

➜ DriverEBV which python 
/usr/local/bin/python 

Moja .zshrc ma następującą linię:

export PATH=/usr/local/bin:$PATH 
export PYTHONPATH="/Library/Python/2.7/site-packages" 

Jest to błąd otrzymuję:

➜ DriverEBV scrapy runspider DriverEBV.py 
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 

Po uruchomieniu "pip rem scrapy" teraz to widzę:

➜ DriverEBV pip install scrapy 
Requirement already satisfied (use --upgrade to upgrade): scrapy in /Library/Python/2.7/site-packages 
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /Library/Python/2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/lib/python2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.8.0 in /Library/Python/2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): lxml in /Library/Python/2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in /Library/Python/2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): service-identity in /Library/Python/2.7/site-packages (from scrapy) 
Requirement already satisfied (use --upgrade to upgrade): cryptography>=0.7 in /usr/local/lib/python2.7/site-packages (from pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/site-packages (from Twisted>=10.0.0->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): characteristic>=14.0.0 in /Library/Python/2.7/site-packages (from service-identity->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): pyasn1-modules in /Library/Python/2.7/site-packages (from service-identity->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): pyasn1 in /Library/Python/2.7/site-packages (from service-identity->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): enum34 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): ipaddress in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): idna>=2.0 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): cffi>=1.1.0 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.7->pyOpenSSL->scrapy) 
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=1.1.0->cryptography>=0.7->pyOpenSSL->scrape) 

Ktoś może mi pomóc?

+0

Prawdopodobny duplikat [Złom scrapy ImportError: nie można zaimportować nazwy xmlrpc \ _client] (http://stackoverflow.com/questions/30964836/scrapy-throws-importerror-cannot-import-name-xmlrpc-client) – eLRuLL

+2

Niestety nie duplikat. Próbowałem wszystkiego, o czym mówiłem w artykule, który napisałeś. Więc spróbowałem prawie wszystkiego innego, co było dostępne online, od najmniej inwazyjnych po najbardziej uciążliwe. –

+0

dlaczego ustawiasz tutaj ścieżkę python? – cel

Odpowiedz

1

Co pomogło mi było deinstalacji sześć i scrapy a następnie zainstalować ponownie:

pip uninstall six 
pip uninstall scrapy 

pip install six 
pip install scrapy 

Uruchom z sudo w razie potrzeby.


Albo można też spróbować uaktualniania sześć i scrapy:

pip install --upgrade scrapy 
pip install --upgrade six 
+0

Myślę, że rozwiązał mój problem podczas uruchamiania scrapy w linii poleceń. podczas działania w PyCharm, pojawia się ten błąd. Wszelkie sugestie do rozwiązania? –

+0

@GuyDaher Czy interpreter projektu w ustawieniach jest prawidłowy? (Wierzę, że w tym przykładzie powinna to być domyślna instalacja pythona) – mkaran

2

miałem nic prócz bólu mucking z bibliotek Pythona systemu Mac OS X zainstalowany w katalogu /Library/Python. Co działa dobrze dla mnie jest kombinacją DarwinPorts i virtualenv:

  1. Install MacPorts

  2. zainstalować Python PIP i virtualenv z DarwinPorts: virtualenv

    /opt/local/bin/port install python27 
    /opt/local/bin/port install py27-pip 
    /opt/local/bin/port install py27-virtualenv 
    
  3. konfiguracji:

    /opt/local/bin/virtualenv-2.7 myenv 
    
  4. Aktywacja virtualenv (nie zapomnij kropki!)

    . myenv/bin/activate 
    
  5. Install scrapy

    pip install scrapy 
    

ten sposób biblioteki systemu Python są nietknięte i można zainstalować pakiety cokolwiek chcesz bez konieczności usunięcia lub uaktualnienia istniejących pakietów.

+0

Myślę, że rozwiązał mój problem podczas uruchamiania scrapy w linii poleceń. podczas działania w PyCharm, pojawia się ten błąd. Wszelkie sugestie do rozwiązania? –

+0

PyCharm wydaje się teraz obsługiwać virtualenv. Powinieneś być w stanie [dodać istniejący virtualenv] (https://www.jetbrains.com/help/pycharm/2016.1/adding-existing-virtual-environment.html) za pośrednictwem [Project Interpreter] (https: // www. .jetbrains.com/help/pycharm/2016.1/project-interpreter.html). Mam nadzieję że to pomoże. –

+0

Tak, wymyśliłem to po opublikowaniu tego komentarza. Dzięki za powyższe informacje, przyznano Ci nagrodę –

-1

Uważam, że najlepszym rozwiązaniem na OS X powinno być "Nie używaj systemowego pythona". Ułatwi to życie. This link pokazuje, jak to zrobić.

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

+0

Czy możesz następnie zainstalować i zaimportować "Scrapy", używając tej metody? – cpburnz

+0

@ cpburnz Bez problemu. Działa idealnie dla mnie. –

0

Spróbuj odinstalować przez pip, a następnie ponownie zainstaluj, używając polecenia easy_install. Miałem ten sam problem z innym modułem Pythona i robiłem to w ten sposób naprawiłem problem na Mac OS X El Capitan.

Powiązane problemy