I'm new to programming, and tried to work through the flask tutorial. http://flask.pocoo.org/docs/tutorial/
I'm stuck on this part (from the readme on github) when trying to run the app: https://github.com/mitsuhiko/flask/tree/master/examples/flaskr/
Fire up a python shell and run this:
from flaskr import init_db; init_db()
I get this error when I try to run the command in python shell:
Import error: No module named flaskr
And I get this error when I try to run app locally:
sqlite3.OperationalError
OperationalError: unable to open database file
I've been looking for solution for several hours now, but to no avail. Any thoughts on what I could check? Thank you.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With