34

I'm working through: http://flask.pocoo.org/docs/1.0/tutorial/

I've written __init__.py (code here: http://codepad.org/4FGIE901) in a /flaskr/ directory, set up a virtual environment called 'venv' and installed Flask.

I then ran these commands — on the command line, in the flaskr directory – as 'Run the application' advises: (export FLASK_APP=flaskr, export FLASK_ENV=development, flask run)

What I should see is Hello, World!

Instead, I'm presented with the following errors:

Traceback (most recent call last):
  File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 330, in __call__
    rv = self._load_unlocked()

  File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 317, in _load_unlocked
    self._app = rv = self.loader()

  File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 372, in load_app
    app = locate_app(self, import_name, name)

  File "/Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages/flask/cli.py", line 246, in locate_app
    'Could not import "{name}".'.format(name=module_name)

flask.cli.NoAppException: Could not import "flaskr.flaskr".

Simply, I'm not sure how I should respond to or work upon fixing an error like this. Perhaps I have a mismatch in what I have installed in the venv and what this particular project requires?

Like this person: Could not Import Pandas: TypeError

Flask:

  • /Users/David/Desktop/flaskr/venv/bin/Flask
  • Version: 1.0.2

Pip:

  • from /Users/David/Desktop/flaskr/venv/lib/python3.6/site-packages (python 3.6)
  • Version: 9.0.1

Python:

  • /Users/David/Desktop/flaskr/venv/bin/python
  • Version: 3.6.0
2
  • Is your cwd the same as where flaskr is stored?
    – ollien
    May 28, 2018 at 23:02
  • I believe so, yes. Typing: stackoverflow.com/a/10783138/9214153 on terminal, within my virtualenv for flaskr offers: '/Users/David/Desktop/flaskr May 29, 2018 at 0:06

3 Answers 3

95

I think you are in the wrong folder. You probably did:

cd flask_tutorial/flaskr

You need to go up to the tutorial folder:

cd ..

You should flask run in the flask_tutorial folder rather than flask_tutorial/flaskr because you want to import flaskr from that folder, not flaskr/flaskr (which doesn't exist).

2
  • 3
    You're absolutely right and this has solved the issue. I was trying to run the app from within the flaskr directory rather than with the flask_tutorial directory. Many, many thanks :) May 29, 2018 at 15:12
  • When I opened my project in VScode I opened the folder with the project and the file init. Thank you for the help @DavidGodwin, it took a while to figure out why it was not working my ``` flask run``` Jan 10, 2021 at 14:05
3

Those running flask for the first time ..This works well for windows

find the location of your folder use cmd please 'mine is cd /users/hp/Desktop'

cd /users/hp/Desktop>set FLASK_APP=hello.py -->file name cd /users/hp/Desktop>set FLASK_ENV=development cd /users/hp/Desktop>flask run

0

I just installed the latest versions of Flask and Werkzeug and everything was fixed:

python -m pip install Flask==2.0.1
python -m pip install Werkzeug==2.0.1

Notes:

  1. I did not use __init__.py
  2. I run flask app as:
set FLASK_ENV=development
set FLASK_APP=app.py
flask run --port 5000

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.