Storm Storm - 3 months ago 19x
Python Question

Flask cli can't import application set with FLASK_APP

Following the Flask 0.11 documentation, I cloned the Flask repo, created a virtualenv, and installed Flask via

pip install flask
. I went into the
directory, set the
environment variable, then executed:

flask run

However, I got the following error:

Traceback (most recent call last):
File "c:\python34\Lib\", line 170, in _run_module_as_main
"__main__", mod_spec)
File "c:\python34\Lib\", line 85, in _run_code
exec(code, run_globals)
File "D:\GitHub\flask\venv\Scripts\flask.exe\", line 9, in <module>
File "d:\github\flask\venv\lib\site-packages\flask\", line 478, in main
cli.main(args=args, prog_name=name)
File "d:\github\flask\venv\lib\site-packages\flask\", line 345, in main
return AppGroup.main(self, *args, **kwargs)
File "d:\github\flask\venv\lib\site-packages\click\", line 696, in main
rv = self.invoke(ctx)
File "d:\github\flask\venv\lib\site-packages\click\", line 1055, in invoke
cmd_name, cmd, args = self.resolve_command(ctx, args)
File "d:\github\flask\venv\lib\site-packages\click\", line 1094, in resolve_command
cmd = self.get_command(ctx, cmd_name)
File "d:\github\flask\venv\lib\site-packages\flask\", line 316, in get_command
rv = info.load_app().cli.get_command(ctx, name)
File "d:\github\flask\venv\lib\site-packages\flask\", line 209, in load_app
rv = locate_app(self.app_import_path)
File "d:\github\flask\venv\lib\site-packages\flask\", line 89, in locate_app
ImportError: No module named 'flaskr'

How do I correctly run the flaskr example?


I was setting FLASK_APP=flaskr. Since I hadn't installed my app as a package in my virtualenv, I needed to add the .py extension.