Search code examples
pythonflaskpython-babelflask-babel

Flask, Babel and python - ImportError: No module named babel


Despite installing babel I am rather amused yet annoyed that Flask and Babel do not work.

pip install babel
pip install Flask-Babel
Traceback (most recent call last):
  File "run.py", line 8, in <module>
    from app import app
  File "/home/ubuntu/workspace//dashboard/app/__init__.py", line 3, in <module>
    from flaskext.babel import Babel
ImportError: No module named babel

Solution

  • Change this

    from flaskext.babel import Babel
    

    to

    from flask.ext.babel import Babel
    

    Note the . before and after 'ext'. The syntax you are using is the old methodology of importing flask extensions. But for the past few versions, flask made it a standard way of importing extensions. Read the last paragraph here