在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python/ python3.7 不能啟動(dòng)pyspider

python3.7 不能啟動(dòng)pyspider

我在python3.7中安裝好了pyspider以后 在命令行中輸入pyspider以后 總是有提示錯(cuò)誤:

File "c:\users\13733\appdata\local\programs\python\python37\lib\site-packages\pyspider\run.py", line 231

async=True, get_object=False, no_input=False):
    ^

SyntaxError: invalid syntax

這個(gè)錯(cuò)真的很奇怪

回答
編輯回答
失魂人

asyncawait從 python3.7 開(kāi)始已經(jīng)加入保留關(guān)鍵字中. 參考: What’s New In Python 3.7, 所以asyncawait不能作為函數(shù)的參數(shù)名.

比如class也是內(nèi)部保留的關(guān)鍵字:

>>> def foo(class=None, bar=None):
  File "<stdin>", line 1
    def foo(class=None, bar=None):
                ^
SyntaxError: invalid syntax

查看都有哪些關(guān)鍵字可以使用keyword模塊, 比如在 python3.6 中:

>>> import keyword
>>> keyword.kwlist
['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']

我們看看 pyspider 的部分源碼:
run.py:

def fetcher(ctx, xmlrpc, xmlrpc_host, xmlrpc_port, poolsize, proxy, user_agent,
            timeout, phantomjs_endpoint, splash_endpoint, fetcher_cls,
            async=True, get_object=False, no_input=False):

這里把async作為參數(shù)名, 所以在 python3.7 下會(huì)報(bào)錯(cuò)的.

綜上, 需要解決這個(gè)問(wèn)題, 可以:

  1. 將自己的 python 版本降低, 比如降到 python3.5
  2. 告訴 pyspider 的作者, 讓作者修改一下代碼, 不要將async 作為參數(shù)名, 使得代碼兼容 python3.7. 參考這個(gè) Pull Request.
2018年5月2日 21:47