Forums

ImportError with Flask app

I have set up my virtualenv to be the same as the one through which my application is working on my home server however I am now getting an import error message claiming that there is no module named whoosh2. The exact same version of whoosh and its dependencies is installed on my virtual env and I am having trouble trying to work out where the issue lies.

Here is my error log:

    2015-08-07 10:46:33,818 :Traceback (most recent call last):
2015-08-07 10:46:33,818 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-08-07 10:46:33,818 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-08-07 10:46:33,818 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-08-07 10:46:33,818 :    self.error(msg, *args, **kwargs)
2015-08-07 10:46:33,818 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-08-07 10:46:33,819 :    self._log(ERROR, msg, args, **kwargs)
2015-08-07 10:46:33,819 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-08-07 10:46:33,819 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-08-07 10:46:33,819 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-08-07 10:46:33,819 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-08-07 10:46:33,820 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-08-07 10:46:33,820 :    self.threadName = threading.current_thread().name
2015-08-07 10:46:33,820 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-08-07 10:46:33,820 :    return _active[_get_ident()]
2015-08-07 10:46:33,820 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-08-07 10:46:33,820 :    app_iterator = self.app(environ, start_response)
2015-08-07 10:46:33,820 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-08-07 10:46:33,820 :    raise e
2015-08-07 10:46:33,820 :ImportError: No module named whoosh2

Just a quick terminology check -- do you really mean you're using a virtualenv? I ask because your web app isn't configured to use a virtualenv at all, it's just picking up the system packages and anything you happen to have installed with pip2.7 install --user XXX or pip install --user XXX

Hi, Thanks for getting back to me. I had though that I had entered the virtualenv path on the web tab but I must have done something wrong. I have now fixed the issue I had by updating the whoosh alchemy system package.

The problem I had was caused by a clash that occurs between flask sqlalchemy and flask whoosh search that is described here http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling. The issue causes flask to keep creating new database sessions and prevents you from delete or updating database entries. This issue has been fixed in more recent versions of whoosh although it seems that the version pre installed on the system packages does not include this fix.

I fixed this updating the system packages with - pip install --user Flask-WhooshAlchemy==0.56.

The error message I was getting was InvalidRequestError: Object '<Post at 0x7f47a968d350>' is already attached to session '1' (this is '5') in case anybody comes across the same issue in the future.

Ah, that makes sense. Thanks for posting the update!