运行Python Flask应用程序时出现“导入错误”

时间:2018-10-06 17:42:41

标签: flask

尝试运行示例Python Flask应用程序时出现以下错误。

Traceback (most recent call last):
  File "/home/bineeth/Projects/python/xcontent/bin/flask", line 7, in <module>
    from flask.cli import main
  File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/flask/__init__.py", line 18, in <module>
    from werkzeug.exceptions import abort
  File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/__init__.py", line 152, in <module>
    __import__('werkzeug.exceptions')
  File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/exceptions.py", line 66, in <module>
    from werkzeug.http import HTTP_STATUS_CODES
  File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/http.py", line 31, in <module>
    from werkzeug.datastructures import (# noqa
  File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/datastructures.py", line 24, in <module>
    from werkzeug.http import dump_options_header, dump_header, generate_etag, \
ImportError: cannot import name 'dump_options_header'

以下为源代码;

from flask import Flask

app = Flask(__name__)

@app.route('/ping')
def ping():
    return {'status':'completed'}

if __name__ == '__main__':
    app.run(debug=False)

我正在使用Python 3和LiClipse IDE。 Linux Mint也是操作系统。 感谢您在这方面的宝贵帮助。

1 个答案:

答案 0 :(得分:0)

您应该尝试重新安装 flask。这将重新安装使用 flask 框架所需的每个包。

试试这些命令:

pip3 uninstall flask
pip3 install flask