Babel: Internationalization Utilities for Python

raw JSON →
2.18.0 verified Tue May 12 auth: no python install: verified quickstart: verified

Babel is a collection of tools for internationalizing Python applications, with an emphasis on web-based applications. The current version is 2.18.0, released on February 26, 2026. Babel follows an annual release cadence, with major updates typically occurring once a year.

pip install babel
error ModuleNotFoundError: No module named 'babel'
cause This error occurs when the 'babel' package is not installed in the Python environment being used, or there's a mismatch between the Python interpreter running the code and where Babel was installed.
fix
Install the Babel library using pip: pip install Babel. If using virtual environments, ensure the correct environment is activated. If multiple Python versions are present, use python -m pip install Babel to ensure installation into the target interpreter.
error AttributeError: 'Babel' object has no attribute 'localeselector'
cause This error typically arises when using Flask-Babel, indicating an incompatibility or incorrect usage of the `localeselector` decorator due to API changes in Flask-Babel v3.0.0 or newer.
fix
Instead of using the @babel.localeselector decorator, pass the locale selector function directly to the Babel constructor or the init_app method, for example: babel = Babel(app, locale_selector=get_locale) or babel.init_app(app, locale_selector=get_locale).
error pybabel: error: no input files or directories specified
cause This error occurs when the `pybabel extract` command is run without specifying the source files or directories from which to extract translatable messages.
fix
Provide the input directory using the --input-dirs option or by adding a dot . to represent the current directory, for example: pybabel extract -F babel.cfg -o messages.pot --input-dirs=..
error RuntimeError: The babel data files are not available.
cause This error indicates that Babel's Common Locale Data Repository (CLDR) files, which contain locale-specific data, are missing. This often happens after a source installation or when certain package managers don't include them.
fix
If installing from source, ensure you run python setup.py import_cldr before python setup.py install. If installed via a package manager, ensure the babel package (or python-babel on some systems) is correctly installed and its data dependencies are met.
error ModuleNotFoundError: No module named 'babel.numbers'
cause This specific ModuleNotFoundError typically occurs when a submodule like `babel.numbers` is used without an explicit import, or when tools like Pyinstaller fail to detect such nested imports during packaging.
fix
Explicitly import the submodule where it's needed, for instance: from babel.numbers import format_decimal. If using Pyinstaller, add --hidden-import babel.numbers to your Pyinstaller command or .spec file.
breaking Babel 2.15.0 dropped support for Python 3.7, requiring Python 3.8 or newer.
fix Upgrade to Python 3.8 or later to maintain compatibility.
deprecated The 'format_datetime' function is deprecated and will be removed in a future release.
fix Use 'format_date' or 'format_time' as appropriate for your use case.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.04s 50.7M
3.10 slim (glibc) - - 0.03s 51M
3.11 alpine (musl) - - 0.07s 52.7M
3.11 slim (glibc) - - 0.05s 53M
3.12 alpine (musl) - - 0.05s 44.5M
3.12 slim (glibc) - - 0.05s 45M
3.13 alpine (musl) - - 0.04s 44.1M
3.13 slim (glibc) - - 0.04s 45M
3.9 alpine (musl) - - 0.04s 50.2M
3.9 slim (glibc) - - 0.03s 51M

This example demonstrates how to set a locale and format a date accordingly using Babel.

from babel import Locale

# Set the locale to French
locale = Locale('fr', 'FR')

# Format a date in the French locale
from babel.dates import format_date
from datetime import datetime

date = datetime(2026, 3, 28)
formatted_date = format_date(date, locale=locale)
print(formatted_date)  # Output: 28 mars 2026