Forums

ImportError: No module named flask_moment

Dear All,

I am facing the following import error from flask_moment import Moment for my Python Flask web app. I have tried from flask.ext.moment import Moment as well but to no avail.

Please kindly guide me into solving my issue, thank you so much for your help! :)

The error log is as below:

2017-06-15 05:34:48,273: Error running WSGI application
2017-06-15 05:34:48,273: ImportError: No module named flask_moment
2017-06-15 05:34:48,273:   File "/var/www/mousehuntglitch_pythonanywhere_com_wsgi.py", line 16, in <module>
2017-06-15 05:34:48,274:     from flask_app import app as application
2017-06-15 05:34:48,274: 
2017-06-15 05:34:48,274:   File "/home/mousehuntglitch/mysite/flask_app.py", line 5, in <module>
2017-06-15 05:34:48,274:     from flask_moment import Moment
2017-06-15 05:34:48,274: ***************************************************
2017-06-15 05:34:48,274: If you're seeing an import error and don't know why,
2017-06-15 05:34:48,275: we have a dedicated help page to help you debug: 
2017-06-15 05:34:48,275: https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-06-15 05:34:48,275: ***************************************************

I have also taken a look at the following document as well: https://help.pythonanywhere.com/pages/DebuggingImportError On my bash console, I have tried the following: pip install flask-moment, pip3.4 install flask-moment, pip install --user flask-moment and pip3.4 install --user flask-moment, and I am able to install all of them, but I still get the same import error.

Additionally, I was able to run this on my bash console:

python3.4 -i /var/www/mousehuntglitch_pythonanywhere_com_wsgi.py

I am also able to run the following successfully:

from flask_moment import Moment

Afterwards, this is what I run and get:

>>> import flask_moment
>>> print(flask_moment)
<module 'flask_moment' from '/home/mousehuntglitch/.local/lib/python3.4/site-packages/flask_moment.py'>
>>> import sys
>>> print('\n'.join(sys.path))
/home/mousehuntglitch/mysite
/var/www
/home/mousehuntglitch/.local/lib/python3.4/site-packages
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/usr/lib/python3.4/lib-dynload
/usr/local/lib/python3.4/dist-packages
/usr/lib/python3/dist-packages

So since /home/mousehuntglitch/.local/lib/python3.4/site-packages is already listed, I should have no problems importing flask-moment, but I still get the import error.

It looks like you've configured your web app to use Python 2.7, not 3.4. Each version of Python has a separate set of installed modules, so installing the package for 3.4 won't help. If you change the Python version to 3.4 on the "Web" tab, then reload your web app, it should work fine.

Thank you giles! I'm a fool for overlooking my Python edition. Everything works great now!