Python3.9安裝PySpider步驟及問題解決


先寫一些前言吧,自己感覺python已經有一定的基礎了,但是在安裝這個過程居然用了一下午,感覺有些收貨,特地寫下來與大家分享一下。

  • PySpider是一個強大的網絡爬蟲系統,GitHub地址:https://github.com/binux/pyspider;官方文檔地址:http://docs.pyspider.org/en/latest
  • PySpider,提供WEBUI系統,支持PhantomJS進行JS的渲染采集,內置pyquery作為選擇器,可拓展程度不高。
  • Scrapy,原生是代碼和命令操作,對接Portia實現可視化,使用parse命令調試,對接Scrapy-Splash組件進行JS渲染采集,對接XPath/CSS選擇器和正則匹配,可對接Middleware、Pipeline、Extension等組件拓展。
  • PySpider,架構分為Scheduler調度器(發起任務調度),Fetcher抓取器(抓取網頁內容),Processer處理器(解析網頁內容)。

話不多說,上安裝過程(PS,本機環境windows10,Python3.9.0):

1、首先需要安裝PhantomJS,這個比較簡單,就直接按照網上流程安裝對應版本就行。

2、安裝PyCurl,這個是安裝PySpider的先決條件,直接pip安裝會報錯,可以下載.whl文件安裝,網址https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycurl

3、安裝PySpider,直接pip安裝就行。

4、安裝調試:

(1)、安裝完Pyspider,命令行運行pyspider,會報錯:SyntaxError: invalid syntax:

這個是因為python以及相關依賴版本過高。可以使用Pycharm (亦可直接用文檔更改代碼),點擊File-Open打開python\lib\sit-packages\pyspider,將文件夾pyspider 加載進去,按Ctrl+Shift+F快捷鍵調出全局搜索,輸入async,即可在“In Project”下找到所有含有關鍵字的.py 文件,逐一打開,按Ctrl+R調出替換欄,將async 替換為shark 即可。就是分別在run.pytornado_fetcher.pywebui>app.py,ctrl+f查找async替換掉就可以了。(注意大寫的Async不要替換)

(2)、再次運行發現報錯:AttributeError: module 'fractions' has no attribute 'gcd'

這個函數在Python3.5之后就廢棄了,官方建議使用math.gcd()。所以在libs/base_handler文件中上方加入 import math下面fractions.gcd()改為math.gcd(…)就可以了

(3)、再次運行發現報錯:Deprecated option 'domaincontroller': use 'http_authenticator.domain_controller' instead.

webui文件里面的webdav.py文件打開,修改第209行即可。把

'domaincontroller': NeedAuthController(app),

修改為:

'http_authenticator':{ 'HTTPAuthenticator':NeedAuthController(app), },

(4)、再次運行發現報錯:cannot import name 'DispatcherMiddleware' from 'werkzeug.wsgi' (d:\python39\lib\site-packages\werkzeug\wsgi.py)

這個是werkzeug的版本太高問題,需要進行修改

python -m pip  uninstall werkzeug # 卸載
python -m pip install werkzeug==0.16.1   #安裝0.16.1版本

(5)、同樣也需要更換wsgidav 版本

pip uninstall wsgidav

pip install wsgidav==2.4.1

(6)、再次運行pyspider,發現卡死在result_worker starting,運行pyspider all卡死在, fetcher starting…

百度,① 有說需要打開一個命令行端口運行pyspider,卡住后運行第二個並關掉第一個端口;② 有說需要關閉防火牆;③ 有說需要先安裝redis

但是,我都嘗試一遍還是卡在那里。

(7)最后選擇重新安裝一遍,

① 把之前安裝的包卸載,具有有:wsgidavwerkzeugpycurlpyspider(已經安裝的redis沒有卸載,防火牆中python權限打開沒關)

② 按照上述(1)~(5)步驟安裝,過程中發現Flask與相關包沖突,並最Flask的版本進行了更新。具體描述如下:

a)發現在安裝 werkzeug 時報錯:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

flask 2.0.1 requires Werkzeug>=2.0, but you have werkzeug 0.16.1 which is incompatible.

b)卸載flask,繼續安裝 wsgidav 時報錯:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.

pyspider 0.3.10 requires Flask>=0.10, which is not installed.

c)安裝 flask==1.0.2 ,如果安裝0.10版本,發現pyspider的網頁UI部分內容渲染失敗。1.0.2版本剛好合適

d)安裝成功截圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM