21

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.

PDiracDelta
  • 2,348
  • 5
  • 21
  • 43

9 Answers9

30

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).

PDiracDelta
  • 2,348
  • 5
  • 21
  • 43
23

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
Chayapol
  • 3,718
  • 1
  • 21
  • 12
8

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.

Community
  • 1
  • 1
Michael Scheper
  • 6,514
  • 7
  • 63
  • 76
7

This message will occur if you issue flask run on the command line. Instead use python -m flask run after setting export FLASK_APP and export FLASK_ENV variables. I ran into this issue while following the Flask Tutorial when creating The Application Factory. The instruction does not specify to preface flask run with python -m.

y2knoproblem
  • 461
  • 6
  • 9
5

This could be many reasons.

python2 vs python3 issue,

pip2 install Flask vs pip3 install Flask issue,

and (venv) virtual environment vs local environment issue.

In my case, had to do the following to solve the problem:

  1. python3 -m venv venv

  2. . venv/bin/activate

  3. pip3 install Flask

  4. export FLASK_APP=flask_app

  5. flask run

Gary Bao 鲍昱彤
  • 2,608
  • 20
  • 31
3

Similar to y2knoproblem, I was following the flask official tutorial, so using an application factory and venv virtual environment. I was able to use

python -m flask run

but this caused issues with my IDE serving to localhost rather than an address accessible externally as it did when I ran 'flask run' on an application.py.

I was able to make this work by specifying

export FLASK_APP=__init__.py

instead of

export FLASK_APP=myapp
1

Please follow these steps:

  1. Make sure you have already done with [pip install --editable . ]. where '.' represent the location of directory where your app is installed. e.g(flask_app)

  2. Run python It will open command line python interpreter

  3. Try to import the flask app If its there error, you will get the detailed error. Try to fix that error.

I do ran into the same problem and followed the steps above and found that there is error in running code. Interpreter is showing compile error.

Pang
  • 9,564
  • 146
  • 81
  • 122
Gopal Prasad
  • 165
  • 7
0

The werkzeug version is not suitable for flask. To address this problem, you need to upgrade the werkzeug, use: $pip install werkzeug --upgrade

Eds_k
  • 944
  • 10
  • 12
0

Same issue here at step 5 of the flask tutorial: http://flask.pocoo.org/docs/0.12/tutorial/dbinit/.

What I did is

1) inside the virtual environment, uninstall the package by pip uninstall flaskr

2) deactivate the virtual environment, then reactivate it by deactivate then source bin/activate

3) re-install the flaskr package by pip install --editable .

4) reset the env variables by export FLASK_APP=flaskr

5) now do flask run and hit localhost:5000 in browser generate the 404 (no view, as expected) error instead of the 500 (file not found) error.

or do flask initdb which triggers the init_db() function as expected

X.X
  • 961
  • 2
  • 12
  • 16