Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask "Error: The file/path provided does not appear to exist" although the file does exist

I use export FLASK_APP=flask_app and then do flask run but I get the error:

Error: The file/path provided (flask_app) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py

However, the file does exist and is even in the present working directory. Using the complete path to the file does not work either.

like image 529
PDiracDelta Avatar asked Jan 28 '17 18:01

PDiracDelta


3 Answers

This situation occurs when you have an ImportError which is not propagated through to your terminal. Check all of your files for invalid import statements, fix them, and the error should disappear.

EDIT 2017-04-02: @Michael pointed out that my reference now placed under the tag "OLD MESSAGE PART 2" is incorrect. I don't know how this mistake came to be, but I've found a very recent post on the Flask Github where they reference the commit that should have fixed the issue on Dec 30th of 2016. Probably at that time I was indeed running an older flask version.

OLD MESSAGE PART 2: This issue is discussed on the Flask Github, though I am unsure as to when and even whether it has actually been fixed, since I still encounter the error today even though I downloaded Flask after the merge of the fix described on that page (12 Aug 2016).

like image 174
PDiracDelta Avatar answered Oct 31 '22 14:10

PDiracDelta


The error message is from flask version 0.x when running with environment variables, just upgrade your flask to version 1.x.

pip install -U flask
like image 24
Chayapol Avatar answered Oct 31 '22 14:10

Chayapol


I see this error when I'm missing an import statement somewhere in my code. The fact that the actual import error isn't shown, in my view, is a bug, as described in @PDiracDelta's answer. (Update: It seems it will be fixed in Flask 0.13.)

A workaround that works for me is specifying the app at the command line. From the error message you've quoted, it looks like your app is called 'flask_app', so just type this:

python flask_app.py

This won't actually run the app (unless it checks if __name__ == '__main__' or something), but it will show the import errors.

like image 8
Michael Scheper Avatar answered Oct 31 '22 16:10

Michael Scheper