You said, that the problem only occurs when you run the code from an interactive shell. It is caused by a feature in werkzeug
(the wsgi server flask
is based on).
In debug mode werkzeug
will automatically restart your server if a project file is changed. Everytime a change is detected werkzeug
restarts the file that was initially started. Even the first start is done via the file name!
But in the interactive shell there is no file at all and werkzeug
thinks your file is called ""
(empty string). It then tries to run that file. For some reason it also thinks that the ""
refers to a package. But since that package does not exist it also cannot have a __main__
module, hence the error.
You can simulate that error by running ""
directly
python ""
# prints: can't find '__main__' module in ''
You could try to disabe the reloader by setting debug to False
(which is also the default):
app.run(debug=False, ...)
Then it should also run in an interactive session. But why would you do that? Just put in a file and run that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…