My project structure is:
/home/giri/couponmonk_project
__init__.py
views.py
__init__.py
from flask import Flask
app = Flask(__name__)
app.debug = True
import couponmonk_project.views
views.py
from couponmonk_project import app
@app.route('/', methods = ['GET'])
def index():
return 'Flask is running!'
When I run:
gunicorn __init__:app -b localhost:8000
from the folder /home/giri/couponmonk_project
I get the error:
ImportError: No module named couponmonk_project.views
I tried adding:
import sys
sys.path.append("/home/giri/couponmonk_project")
to my __init__.py file but still get the same error.
Even if this had worked, is appending to sys.path the proper way of doing this?
I have read that appending to sys and PYTHONPATH may not be the best way to fix the issue.
As it has been stated in the above comments you have a circular dependency. To avoid it, you should make your current
couponmonk_projectas module, that will be run by another python script. According to the Flask documentation your project should look like:where inner folder
couponmonk_projectis your present project, and outer foldercouponmonk_projectis the new one. Thus, file/home/giri/couponmonk_project/__init__.pyshould be something like:and your file
/home/giri/couponmonk_project/coupon_monk/project__init__.pyis: