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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0