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)
The extension in the FLASK_APP env variable is removed in the documentation.
export FLASK_APP=flaskrshould beexport FLASK_APP=flaskr.pyThat 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:
Will never work because there is no way for Python to find the flaskr.py file. The fix we are using is:
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:
more reference
Then
flask runin 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/flaskrEnvironment 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:
Sent from my Android device with K-9 Mail. Please excuse my brevity.