Forums

Import error

Hi,

somehow I can't import "mail and app" from run.py. The latter initializes my flask app by "app = create_app(config_mode)" and and mail by "mail=Mail(app)" and is needed in other own modules like in "/app/base/routes.py".

Any idea how to solve that?

2021-01-21 08:22:47,464: Error running WSGI application
2021-01-21 08:22:47,476: ImportError: cannot import name 'mail' from 'run' (/home/appboost1/mysite/run.py)
2021-01-21 08:22:47,477:   File "/var/www/appboost1_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-01-21 08:22:47,477:     from run import app as application  # noqa
2021-01-21 08:22:47,477: 
2021-01-21 08:22:47,477:   File "/home/appboost1/mysite/run.py", line 28, in <module>
2021-01-21 08:22:47,477:     app = create_app(config_mode)
2021-01-21 08:22:47,477: 
2021-01-21 08:22:47,477:   File "/home/appboost1/mysite/app/__init__.py", line 81, in create_app
2021-01-21 08:22:47,477:     register_blueprints(app)
2021-01-21 08:22:47,477: 
2021-01-21 08:22:47,477:   File "/home/appboost1/mysite/app/__init__.py", line 23, in register_blueprints
2021-01-21 08:22:47,478:     module = import_module('app.{}.routes'.format(module_name))
2021-01-21 08:22:47,478: 
2021-01-21 08:22:47,478:   File "/home/appboost1/mysite/app/base/routes.py", line 14, in <module>
2021-01-21 08:22:47,478:     from app.home.routes import send_mail_async
2021-01-21 08:22:47,478: 
2021-01-21 08:22:47,478:   File "/home/appboost1/mysite/app/home/routes.py", line 26, in <module>
2021-01-21 08:22:47,479:     from run import mail, app
2021-01-21 08:22:47,479: ***************************************************
2021-01-21 08:22:47,479: If you're seeing an import error and don't know why,
2021-01-21 08:22:47,479: we have a dedicated help page to help you debug: 
2021-01-21 08:22:47,479: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-01-21 08:22:47,479: ***************************************************

I also created yesterday a topic and I am not sure if it got saved. I couldn't find it anymore. Sorry if this is redundant.

Yes, I already answered there -- shall we delete this thread?