Hello,
I'm trying to add dash instance to a flask app, but struggle with WGSI import.
WGSI doesn't want to import the dash module while it's installed and works well when I run directly the file Flask_app.py.
The /var/www/pythonanywhere_com_wsgi.py
import sys
# add your project directory to the sys.path
project_home = '/home/mysite'
if project_home not in sys.path:
sys.path = [project_home] + sys.path
# import flask app but need to call it "application" for WSGI to work
from flask_app import app as application # noqa
The /home/mysite/flask_app.py
from flask import Flask, render_template
import dash
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello from Flask!
# Set-up endpoint 1
app_1 = dash.Dash(name='app1', server=app, url_base_pathname='/app1/')
app_1.layout = html.H1('App 1')
The error:
Error running WSGI application
2021-12-14 16:16:26,591: ModuleNotFoundError: No module named 'dash'
2021-12-14 16:16:26,591: File "/var/www/pythonanywhere_com_wsgi.py", line 16, in <module>
2021-12-14 16:16:26,591: from flask_app import app as application # noqa
2021-12-14 16:16:26,591:
2021-12-14 16:16:26,592: File "/home/mysite/flask_app.py", line 5, in <module>
2021-12-14 16:16:26,592: import dash
2021-12-14 16:16:26,592: ***************************************************
2021-12-14 16:16:26,592: If you're seeing an import error and don't know why,
2021-12-14 16:16:26,592: we have a dedicated help page to help you debug:
2021-12-14 16:16:26,592: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-12-14 16:16:26,592: ***************************************************
I tried with an other module and it's the same behavior:
2021-12-14 16:47:51,730: Error running WSGI application
2021-12-14 16:47:51,734: ModuleNotFoundError: No module named 'pandas'
2021-12-14 16:47:51,734: File "/var/www/pythonanywhere_com_wsgi.py", line 17, in <module>
2021-12-14 16:47:51,734: from flask_app import app as application # noqa
2021-12-14 16:47:51,734:
2021-12-14 16:47:51,735: File "/home/mysite/flask_app.py", line 5, in <module>
2021-12-14 16:47:51,735: import pandas
2021-12-14 16:47:51,735: ***************************************************
2021-12-14 16:47:51,735: If you're seeing an import error and don't know why,
2021-12-14 16:47:51,735: we have a dedicated help page to help you debug:
2021-12-14 16:47:51,735: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-12-14 16:47:51,735: ***************************************************