Forums

Flask import error (ImportError: cannot import name db)

The app works fine locally. I uploaded all files and updated the WSGI file. Now I get an import error. I am using sqlite and sqlalchemy. I believe I've installed the right requirements (listed below). Any ideas?


2015-02-22 01:11:29,802 :/usr/lib/python2.7/threading.py:1160: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
2015-02-22 01:11:29,803 :  return _active[_get_ident()]
2015-02-22 01:11:29,803 :Traceback (most recent call last):
2015-02-22 01:11:29,803 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-02-22 01:11:29,803 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-02-22 01:11:29,803 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-02-22 01:11:29,804 :    self.error(msg, *args, **kwargs)
2015-02-22 01:11:29,804 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-02-22 01:11:29,804 :    self._log(ERROR, msg, args, **kwargs)
2015-02-22 01:11:29,804 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-02-22 01:11:29,804 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-02-22 01:11:29,804 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-02-22 01:11:29,805 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-02-22 01:11:29,805 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-02-22 01:11:29,805 :    self.threadName = threading.current_thread().name
2015-02-22 01:11:29,805 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-02-22 01:11:29,805 :    return _active[_get_ident()]
2015-02-22 01:11:29,805 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-02-22 01:11:29,805 :    app_iterator = self.app(environ, start_response)
2015-02-22 01:11:29,805 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-02-22 01:11:29,806 :    raise e
2015-02-22 01:11:29,806 :ImportError: cannot import name db

Creoleparser==0.7.4
DateTime==4.0.1
Flask==0.10.1
Flask-Bootstrap==3.0.3.1
Flask-HTTPAuth==2.2.0
Flask-Login==0.2.7
Flask-Mail==0.9.0
Flask-Migrate==1.1.0
Flask-Moment==0.2.1
Flask-OAuthlib==0.7.0
Flask-OpenID==1.2.4
Flask-PageDown==0.1.4
Flask-Principal==0.4.0
Flask-SQLAlchemy==1.0
Flask-Script==0.6.6
Flask-Security==1.7.4
Flask-Uploads==0.1.3
Flask-WTF==0.9.4
Flask-WhooshAlchemy==0.56
ForgeryPy==0.1
Genshi==0.7
Jinja2==2.7.1
Mako==0.9.1
Markdown==2.3.1
MarkupSafe==0.18
MySQL-Connector-Python==2.0.2
PIL==1.1.7
Pillow==2.0.0
Pygments==1.6
SQLAlchemy==0.8.4
WTForms==1.0.5
Werkzeug==0.9.6
Whoosh==2.6.0
alembic==0.6.2
amqp==1.4.6
anyjson==0.3.3
argparse==1.2.1
billiard==3.3.0.19
bleach==1.4
blinker==1.3
ccy==0.6.1
celery==3.1.17
colorama==0.2.7
coverage==3.7.1
flask-peewee==0.6.6
google-api-python-client==1.3.1
gunicorn==19.1.1
html5lib==1.0b3
httpie==0.7.2
httplib2==0.9
itsdangerous==0.23
kombu==3.0.24
oauth2client==1.4.6
oauthlib==0.7.2
passlib==1.6.2
pbr==0.10.0
peewee==2.4.2
psycopg2==2.5.4
pyasn1==0.1.7
pyasn1-modules==0.0.5
python-dateutil==2.4.0
python-gflags==2.0
python-openid==2.2.5
pytz==2014.7
redis==2.10.3
requests==2.1.0
rsa==3.1.4
selenium==2.39.0
simplejson==3.6.5
six==1.9.0
stevedore==1.1.0
uritemplate==0.6
virtualenv==1.9.1
virtualenv-clone==0.2.5
virtualenvwrapper==4.3.1
virtualenvwrapper-win==1.1.5
wtf-peewee==0.2.3
zope.interface==4.1.1

Does this help? https://www.pythonanywhere.com/wiki/DebuggingImportError

The problem was a circular import. To solve the problem in my app.py file I placed the other imports which are dependent on 'db' below db=SQLAlchemy(app). Thanks for the response.

:)

This did the trick: $ python3.6 -i /var/www/www_my_domain_com_wsgi.py