简体   繁体   English

“从 flask 导入烧瓶”中的语法错误

[英]Syntax error in 'from flask import Flask'

After installing Flask, When I used安装 Flask 后,当我使用

from flask import Flask

to check if flask is properly installed or not, it gave the following error检查 flask 是否正确安装,它给出了以下错误

>>> from flask import Flask
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/flask/__init__.py", line 3, in <module>
    from werkzeug.exceptions import abort
  File "/usr/local/lib/python3.5/dist-packages/werkzeug/__init__.py", line 1, in <module>
    from .serving import run_simple
  File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 151
    server: "BaseWSGIServer"
          ^
SyntaxError: invalid syntax

How to solve this issue.如何解决这个问题。

The error indicates that you're running Python 3.5.该错误表明您正在运行 Python 3.5。 Variable annotations that the library is attempting to use weren't introduced until 3.6 though .库尝试使用的变量注释直到 3.6 才引入

Upgrade to at least 3.6 to solve this.升级到至少 3.6 来解决这个问题。 3.9 is available too, so unless you need to use an older version for some reason, you might as well just to a full upgrade of your version. 3.9 也可用,所以除非您出于某种原因需要使用旧版本,否则您还不如完全升级您的版本。

Flask is now at 2.0.0, and has ratcheted forward on requirements. Flask 现在是 2.0.0,并且在要求方面已经向前推进。

If you're on a system that is still on Python3.5, you are out of luck for 2.0.0.如果您使用的系统仍在 Python3.5 上,那么您对 2.0.0 不走运。 Your alternative is to install the most recent in the 1.x line.您的替代方法是安装 1.x 行中的最新版本。

Specify指定

Flask==1.4.4

if you're using requirements.txt , or如果您使用requirements.txt ,或者

venv/bin/pip install Flask==1.1.4

to install it manually.手动安装它。

Flask is now at 2.0.0, which has ratcheted forward on requirements. Flask 现在是 2.0.0,它已根据要求向前推进。

If you're on a system that is still on Python3.5, your alternative is to install the most recent in the 1.x line, and put如果您使用的系统仍在 Python3.5 上,您的替代方法是安装 1.x 行中的最新版本,然后将

Flask==1.1.4

in your requirements.txt , or在您的requirements.txt中,或

venv/bin/pip install Flask==1.1.4

to install it manually.手动安装它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM