File structure
__pycache__/
data/
pages/
index.py
__init__.py
page_1.py
run.py
Code in run.py
import pages.index as index
if __name__ == '__main__':
index.app.run_server(debug=True)
code in /var/www/test_pythonanywhere_com_wsgi.py
# This file contains the WSGI configuration required to serve up your
# web application at http://<your-username>.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# The below has been auto-generated for your Flask project
import sys
# add your project directory to the sys.path
project_home = '/home/test/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 weber_dashboard import run
application = run.server
Error log
2022-04-29 15:07:21,843: Error running WSGI application
2022-04-29 15:07:21,846: ModuleNotFoundError: No module named 'pages'
2022-04-29 15:07:21,847: File "/var/www/test_pythonanywhere_com_wsgi.py", line 16, in <module>
2022-04-29 15:07:21,847: from weber_dashboard import run
2022-04-29 15:07:21,847:
2022-04-29 15:07:21,847: File "/home/lataigmbh/mysite/weber_dashboard/run.py", line 1, in <module>
2022-04-29 15:07:21,847: import pages.index as index
2022-04-29 15:07:21,847: ***************************************************
2022-04-29 15:07:21,848: If you're seeing an import error and don't know why,
2022-04-29 15:07:21,848: we have a dedicated help page to help you debug:
2022-04-29 15:07:21,848: https://help.pythonanywhere.com/pages/DebuggingImportError/
2022-04-29 15:07:21,848: ***************************************************
run.py script run perfectly fine in bash console
The problem was solved by adding the below line on all the pages and calling the module directly.
import sys
sys.path.append('/.../application/app/folder')
import file_1