python3.7啟動pyspider時報錯的問題
版權聲明:本文為博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
- 關鍵字問題
最后一句出現
File “D:\installed\Python\Lib\site-packages\pyspider\run.py”, line 231
async=True, get_object=False, no_input=False):
SyntaxError: invalid syntax
原因是:python3.7中async是關鍵字
解決辦法是將這個關鍵字替換掉。主要有兩個文件:D:\installed\Python\Lib\site-packages\pyspider\run.py 和 D:\installed\Python\Lib\site-packages\pyspider\fetcher\tornado_fetcher.py
在替換是要注意:只替換名為async 的變量或參數名。不要圖省事選擇“全部替換”
替換保存后再次運行“pyspider all”
這時spider只啟動到“scheduler xmlrpc listening on 127.0.0.1:23333”就停止了
繼續替換PYTHON_HOME\Lib\site-packages\pyspider\webui\app.py中的async
再次啟動
又報錯:ValueError: Invalid configuration:
-Deprecated option ‘domaincontroller’: use ‘http_authenticator.domain_controller’ instead.
解決辦法:打開PYTHON_HOME\Lib\site-packages\pyspider\webui\webdav.py文件,修改第209行
把 ‘domaincontroller’: NeedAuthController(app)
修改為:
‘http_authenticator’:{
‘HTTPAuthenticator’:NeedAuthController(app),
},
保存文件
再次運行,成功 - 這是我遇到的,然后網上居然沒有特別明顯的解決,費勁千辛萬苦才查到,這是WsgiDAV發布了版本 pre-release 3.x導致的,所以只要把版本降下來就好了。
將wsgidav替換為2.4.1
•# python -m pip install wsgidav==2.4.1
直接pip install wsgidav-2.4.1就會卸載3.0.0裝2.4.1
然后運行 pyspider all 發現居然可以了。上一張成功的圖片。
然后很歡快的打開瀏覽器輸入:localhost:5000 -
-
6、如果是在windows環境下,系統會提示 FutureWarning: timeout is not supported on your platform. warnings.warn(“timeout is not supported on your platform.”, FutureWarning),忽略即可。
-
pyspider_安裝與啟動
pyspider
1、安裝
- (1)pip install pycurl
- (2)pip install pyspider
2、pyspider命令啟動錯誤,出現"SyntaxError:invalid syntax"報錯。
- (1) 原因:async在Python 3.7中已成為關鍵字,
- (2) 解決方法:
A、打開pyspider文件夾(在python路徑下python位置\Lib\site-packages\pyspider) B、修改下列python文件中的async為shark(全部替換),pycharm中用ctrl+r快捷鍵可以進行替換。 run.py fetcher\tornado_fetcher.py webui\app.py
A、打開pyspider文件夾(在python路徑下python位置\Lib\site-packages\pyspider)
B、修改下列python文件中的async為shark(全部替換),pycharm中用ctrl+r快捷鍵可以進行替換。
run.py
fetcher\tornado_fetcher.py
webui\app.py3、pyspider命令啟動錯誤,出現"ValueError: Invalid configuration"報錯。
- (1)原因:WsgiDAV發布了版本 pre-release 3.x導致
- (2)解決方法:
python -m pip install wsgidav==2.4.1
- 1
4、pyspider命令啟動錯誤,出現"phantomjs"報錯。
- (1)原因:未安裝phantomjs
- (2)解決方法:
A、下載phantomjs安裝: 下載地址:https://phantomjs.org/download.html B、一路next安裝,將安裝路徑:D:\Software\phantomjs-2.1.1\bin添加到環境變量path里面。 C、打開並找到bin文件夾里的 phantomjs.exe,點擊運行;出現phantomjs>即安裝成功。
- 1
- 2
- 3
5、命令窗口輸入pyspider;瀏覽器輸入:http://localhost:5000/
- (1)命令窗口輸入pyspider,出現如下界面,即🆗。
- (2)瀏覽器輸入:http://localhost:5000/ ,出現如下界面,即🆗。