Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'from flask import Flask' throws up a syntax error - Python

Tags:

python

flask

I just tried a simple hello world app in Python using Flask (From Flask's documentation). I installed Flask using 'pip install flask'. I uninstalled it and installed it again. Still, the issue persists.

Code:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

Error:

Traceback (most recent call last):
  File "HelloWorld.py", line 1, in <module>
    from flask import Flask
  File "C:\Python32\lib\site-packages\flask\__init__.py", line 17, in <module>
    from werkzeug.exceptions import abort
  File "C:\Python32\lib\site-packages\werkzeug\__init__.py", line 154, in <module>
    __import__('werkzeug.exceptions')
  File "C:\Python32\lib\site-packages\werkzeug\exceptions.py", line 111
    return u'<p>%s</p>' % escape(self.description)
                      ^
SyntaxError: invalid syntax
like image 252
Ken Avatar asked Dec 05 '22 06:12

Ken


1 Answers

Flask does not support Python 3.2; only 3.3+ (and 2.6+)

So you need to install a supported Python version.

like image 83
Oleh Prypin Avatar answered Dec 08 '22 05:12

Oleh Prypin