pythonflaskflask-cli

Why running flask application using python instead of Flask-CLI produces ImportError?


When I run my application using flask-cli, the app starts normally.

I set HOST and PORT env variables and run it like:

flask run --host ${HOST} --port ${PORT} --no-reload --no-debugger

PROBLEM:

When I run it like python3.6 main.py, I get some import errors (which I don't get using flask-cli):

Traceback (most recent call last):
  File "main.py", line 21, in <module>:
    from runn.models import User, Town
  File "/home/dinko/my-app/runn/models.py", line 9, in <module>
    from main import db
  File "/home/dinko/my-app/runn/main.py", line 21, in <module>
    from runn.models import User, Town
ImportError: cannot import name `User`

I know it maybe due to the circular imports, but I'm not sure how it works using flask-cli. Is there any solution to run it like with flask-cli, but using python3.6 main.py instead ?


Solution

  • I managed to find a way how to run my flask app by using python -m flask run.