由于目前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
1
2
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’]