python flask import error


I am running the following code

from flask import Flask
app = Flask(__name__)
def hello():
    return "Hello World!"
if __name__ == "__main__":'', port=80, debug=True)

and getting the following error

Traceback (most recent call last):
  File "", line 1, in <module>
    from flask import Flask
  File "/home/pi/programs/", line 1, in <module>
    from flask import Flask
ImportError: cannot import name Flask

I have tried installing flask through various methods , but still the problem persists

also, is there any alternative to flask???

2/9/2013 11:37:50 PM

Accepted Answer

Just run apt-get install python3-flask

Edited to install the python3 version, since nobody should be using python2 now.

3/6/2019 7:37:43 AM

I ran into this error because I named the test file as and tried to run it! It creates namespace conflict with the real flask module!

Delete the local test file that you named and the respective flask.pyc. Give some other name! This will happen with other modules like socket etc where you are likely to give the same name for the test file as the standard module :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow