运行pyspider时出现 : ImportError: cannot import name ‘ContextVar‘

Posted 别呀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行pyspider时出现 : ImportError: cannot import name ‘ContextVar‘相关的知识,希望对你有一定的参考价值。

运行pyspider常见的错误:
①ValueError: Invalid configuration: - Deprecated option ‘domaincontroller’: use ‘http_authenticator.domain_controller’ instead.
②ImportError: cannot import name ‘DispatcherMiddleware’
这里我就不写了,网上一搜还挺多的,就这个问题我在网上找了好长时间也没有找到解决方案。为了大家在遇到相同问题时能够少花点时间,我这里就把我的解决思路分享给大家参考。

这是我运行pyspider命令时出现的错误(我在解决上面提的两个错误后出现这个错误):

PS D:\\python test\\pyspider_text> pyspider
d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\libs\\utils.py:196: FutureWarning: timeout is not supported on your platform.
  warnings.warn("timeout is not supported on your platform.", FutureWarning)
[W 210717 17:50:00 run:413] phantomjs not found, continue running without it.
[I 210717 17:50:02 result_worker:49] result_worker starting...
[I 210717 17:50:02 processor:211] processor starting...
[I 210717 17:50:02 scheduler:647] scheduler starting...
[I 210717 17:50:02 scheduler:586] in 5m: new:0,success:0,retry:0,failed:0
[I 210717 17:50:03 scheduler:782] scheduler.xmlrpc listening on 127.0.0.1:23333
[I 210717 17:50:04 tornado_fetcher:638] fetcher starting...
[I 210717 17:50:04 tornado_fetcher:671] fetcher exiting...
[I 210717 17:50:04 scheduler:663] scheduler exiting...
[I 210717 17:50:04 result_worker:66] result_worker exiting...
[I 210717 17:50:04 processor:229] processor exiting...
Traceback (most recent call last):
  File "d:\\software\\python\\python36\\lib\\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\\software\\python\\python36\\lib\\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\\SoftWare\\Python\\Python36\\Scripts\\pyspider.exe\\__main__.py", line 7, in <module>
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\run.py", line 754, in main
    cli()
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 1236, in invoke
    return Command.invoke(self, ctx)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\run.py", line 165, in cli
    ctx.invoke(all)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\run.py", line 497, in all
    ctx.invoke(webui, **webui_config)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\click\\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\run.py", line 333, in webui
    app = load_cls(None, None, webui_instance)
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\run.py", line 48, in load_cls
    return utils.load_object(value)
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\libs\\utils.py", line 369, in load_object
    module = __import__(module_name, globals(), locals(), [object_name])
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\webui\\__init__.py", line 8, in <module>
    from . import app, index, debug, task, result, login
  File "d:\\software\\python\\python36\\lib\\site-packages\\pyspider\\webui\\app.py", line 16, in <module>
    from flask import Flask
  File "d:\\software\\python\\python36\\lib\\site-packages\\flask\\__init__.py", line 7, in <module>
    from .app import Flask as Flask
  File "d:\\software\\python\\python36\\lib\\site-packages\\flask\\app.py", line 19, in <module>
    from werkzeug.local import ContextVar
ImportError: cannot import name 'ContextVar'

遇到这个情况你可以看下你在成功执行pip install werkzeug==0.16.0语句时,有没有出现下面情况

这个是你flask版本的问题,你只要降低下flask版本就行了

pip uninstall flask   #卸载  你也可以省略这步,直接pip install flask==1.0
pip install flask==1.0   #我这里改成1.0就行了,改成其他低版本应该也没问题,有兴趣自己试下

修改flask版本后:

以上是关于运行pyspider时出现 : ImportError: cannot import name ‘ContextVar‘的主要内容,如果未能解决你的问题,请参考以下文章

运行 adb 命令时出现问题 / 使用平板设备进行开发时出现问题

windows64位如何安装pyspider并运行

运行查询以创建表时出现错误 1064?

pyspider总结

运行 Pig 脚本时出现异常

使用 htdocs xampp 运行命令时出现以下错误