1. 程式人生 > >python3.7 scrapy crawl 報錯

python3.7 scrapy crawl 報錯

python3.7 scrapy crawl name 報錯

由於目前python最新版是3.7,之前電腦裝了3.6,後面由於pip3 install module時報錯,就更新到了3.7,使用scrapy爬取資料時,在執行時報錯,異常內容為:
from twisted.conch import manhole, telnet
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/conch/manhole.py”, line 154
def write(self, data, async=False):
^
SyntaxError: invalid syntax

語法錯誤:無效的語法,報錯內容指在 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twisted/conch/manhole.py 下面,找到此檔案,點選進去,找到 def write(self, data, async=False)此行。
全域性選中 async ,把它替換為一個其他字元即可。
由於python3.7中把 syntax 當成關鍵字了,關鍵字當作引數,報錯丟擲異常了。

查詢python中的關鍵字

import keyword
keyword.kwlist

python3.7的關鍵字

[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘async’, ‘await’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’,’or’, ‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’];

python3.6的關鍵字

[‘False’, ‘None’, ‘True’, ‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘nonlocal’, ‘not’, ‘or’, ‘pass’, ‘raise’, ‘return’, ‘try’, ‘while’,’with’, ‘yield’]