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

Tampa picture Tampa · Oct 10, 2013 · Viewed 14.8k times · Source

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

Answer

codegeek picture codegeek · Oct 10, 2013

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