flaskr tutorial; can't import flaskr (initialize database) flaskr tutorial; can't import flaskr (initialize database) flask flask

flaskr tutorial; can't import flaskr (initialize database)


The thing that fixed it for me was changing

export FLASK_APP=flaskr

to

export FLASK_APP=flaskr.py

Taken from here


The simplest way to accomplish what you need is to fire up the Python shell in the same folder as you have flaskr:

# I'm assuming that python is available on the command line$ cd path/to/flaskr$ python# Python then runs and you can import flaskr>>> from flaskr import init_db; init_db()>>> exit()

The trick is that when you run Python it only looks in a certain number of places for modules and packages - you can see which places by running:

>>> from sys import path>>> for fp in path:...     print fp

from the Python interpreter. If the path to flaskr is not in that list flaskr can't be imported. By default Python adds the directory it is started in to its search path (which is why we start Python in the directory that contains flaskr.)

Once you have run init_db you should be able to run the application and see everything working.


If you're using a version of Flask < 0.11, the flask command is not available. Install the flask-cli package in that case.

pip install flask-cli