Python 3.6 Flask ImportError:无法导入名称“ flash”

时间:2018-11-09 11:24:12

标签: python-3.x flask conda airflow

尝试运行ImportError: cannot import name 'flash'命令时,我总是遇到错误airflow webserver

已安装了各种软件包,包括flask-login,flask,flask-cache,flask-wtf等。这是在没有Internet连接的服务器上,我不得不手动传输这些软件包并运行conda install <package> --offline

完整追溯

/usr/local/anaconda/lib/python3.6/site-packages/flask_cache/jinja2ext.py:33: ExtDeprecationWarning: Importing flask.ext.cache is deprecated, use flask_cache instead.
  from flask.ext.cache import make_template_fragment_key
Traceback (most recent call last):
  File "/usr/local/anaconda/bin/airflow", line 27, in <module>
    args.func(args)
  File "/usr/local/anaconda/lib/python3.6/site-packages/airflow/bin/cli.py", line 678, in webserver
    app = cached_app(conf)
  File "/usr/local/anaconda/lib/python3.6/site-packages/airflow/www/app.py", line 161, in cached_app
    app = create_app(config)
  File "/usr/local/anaconda/lib/python3.6/site-packages/airflow/www/app.py", line 59, in create_app
    from airflow.www import views
  File "/usr/local/anaconda/lib/python3.6/site-packages/airflow/www/views.py", line 46, in <module>
    from flask_login import flash
ImportError: cannot import name 'flash'

谢谢。

1 个答案:

答案 0 :(得分:2)

正如我在评论中所写,python库flask-login没有名为flash的模块或函数。因此,您无法编写代码,该代码位于views.py中的第46行:

from flask-login import flash

但是,该函数存在于python库flask中。因此更改为:

from flask import flash