Forums

ImportError: cannot import name Flask

I'm getting this error after my most recent git pull:

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

I've tried making sure that the virtualenv matches the one I'm using to develop on but it hasn't fixed the error. This is the requirements.txt:

aniso8601==1.0.0
blinker==1.4
Flask==0.10.1
Flask-Admin==1.3.0
Flask-Login==0.2.11
Flask-Mail==0.9.1
flask-mongoengine==0.7.1
Flask-Principal==0.4.0
Flask-PyMongo==0.3.1
Flask-RESTful==0.3.4
Flask-Security==1.7.4
Flask-WTF==0.12
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
mongoengine==0.10.0
passlib==1.6.5
pymongo==2.9
pytz==2015.6
six==1.10.0
Werkzeug==0.10.4
WTForms==2.0.2

The only place in my code that imports Flask is in app.py:

from flask import Flask
from flask.ext.pymongo import PyMongo
from flask.ext.login import LoginManager

app = Flask(__name__)
app.config.from_object('config')
mongo = PyMongo(app)

login_manager = LoginManager()
login_manager.init_app(app)

import views
import api
import admin

Any help gratefully received! Thanks.

]\/[artin

OK, light-bulb moment. The root directory of the app is /home/mhstptest/flask. This has not been a problem until now but it seems that it is now on the sys-path and is masking the "real" flask library. Changing it's name to flask-app (for instance) fixes the import error!

]\/[artin