flask: Import error with some examples

I’m trying to run the “flaskr” and “minitwit” examples, but I’m running into an import error issue. I’m trying to follow the instructions from the README file. When running flask initdb, I get the following error:

Traceback (most recent call last):
  File "/home/nelson/apps/miniconda/bin/flask", line 6, in <module>
    sys.exit(flask.cli.main())
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/flask/cli.py", line 478, in main
    cli.main(args=args, prog_name=name)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/flask/cli.py", line 345, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/click/core.py", line 1055, in invoke
    cmd_name, cmd, args = self.resolve_command(ctx, args)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/click/core.py", line 1094, in resolve_command
    cmd = self.get_command(ctx, cmd_name)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/flask/cli.py", line 316, in get_command
    rv = info.load_app().cli.get_command(ctx, name)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/flask/cli.py", line 209, in load_app
    rv = locate_app(self.app_import_path)
  File "/home/nelson/apps/miniconda/lib/python3.4/site-packages/flask/cli.py", line 89, in locate_app
    __import__(module)
ImportError: No module named 'flaskr'

I’m using an Anaconda Python install on both Windows 10 (Python 3.5) and Linux (Python 3.4) with either the stock flask 0.11 install or an install from the latest git repo. I’m running this code from appropriate directory and am able to import flaskr or minitwit from a terminal Python session. I can run the other examples that do not require the flask script.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 30 (15 by maintainers)

Commits related to this issue

Most upvoted comments

The extension in the FLASK_APP env variable is removed in the documentation.

export FLASK_APP=flaskr should be export FLASK_APP=flaskr.py

That seems to have fixed it for me.

At the present time there is no way for anybody to complete the Flask tutorial - its broken because of this issue. Inside or outside of a virtualenv, on Python 2.7 or 3.5, the “flask run” command will not be able to find the flaskr.py and thus won’t work. These steps:

export FLASK_APP=flaskr
export FLASK_DEBUG=1
flask run

Will never work because there is no way for Python to find the flaskr.py file. The fix we are using is:

export PYTHONPATH=`pwd`

Or similar, and then of course the tutorial works. In the past the tutorial used to involve using python to run the flaskr.py file itself, not sure why this changed to the ‘flask’ binary but the change means people can’t complete the tutorial…thereby damaging Flask’s reputation!

I had successfully run the “flaskr” and “minitwit” examples on Windows 10 (Python 3.5) with commands:

$ set FLASK_APP=flaskr
$ python -m flask initdb
$ python -m flask run

more reference

export FLASK_APP=flaskr.py
export FLASK_DEBUG=1
flask run

Then flask run in the flaskr directory works just fine. But yes, the docs and example do need some updating. (See PR in my comment above.)

The flaskr example should be modified to include a proper setup.py.

I had a hard time with this. I hate to use this as a support forum, but maybe this helps someone else (as of April 2018) if they are googling for help.

I’m on Fedora 27 using pkg version of python3 (3.6.5 as of writing) + flask Follow all the tutorial instructions up to the point where you set ENV variables - then do this: `` export FLASK_APP=flaskr export FLASK_DEBUG=1 #if you want debug out export FLASK_ENV=development python3 -m flask initdb python3 -m flask run

``

Oh and login is “admin”,“default”

Ok 0.12 is out, hopefully I’ll never get emails from this thread again 😛

I’m on a Mac and doing the tutorial in a miniconda environment. I think the miniconda environment broke things for me.

Not a solution I’ve seen here so I’m sharing. Hardcoding the FLASK_APP path did the trick for me:

export FLASK_APP=~/miniconda/envs/myenv/myenv/flask-tutorial/flaskr

Environment variables are always a hassle. 😕

I solved this issue running the command at the same folder where init.py and flaskr.py are placed.

This is fixed in master I think, via #1945 and #1954. Thanks @wgwz for the excellent work!

Docs are only updated at release time, in principle. We should do a bugfix release soon.

On 31 July 2016 12:33:23 CEST, tigertailzlc notifications@github.com wrote:

I see that the Flaskr tutorial for the development version of Flask has been updated, but that the equivalent 0.11 tutorial has not. Does this mean that the Flask 0.11 Flaskr tutorial will be permanently unusable?

If so, perhaps it would be good to update the Flask website so that someone clicking through the homepage->docs->tutorial does not end up on the 0.11 tutorial version?


You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/pallets/flask/issues/1902#issuecomment-236422669

Sent from my Android device with K-9 Mail. Please excuse my brevity.