Install & Compatibility
Where this runs
tested against v2.18.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.044s · 50.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.1s · import 0.036s · 51MB
49MB installed
● package 49MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
format_date
✓ from babel.dates import format_date
Ensure correct import path to access date formatting functions
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
pybabel --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'babel'
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.
fixInstall 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.
AttributeError: 'Babel' object has no attribute 'localeselector'
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.
fixInstead 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)`.
pybabel: error: no input files or directories specified
This error occurs when the `pybabel extract` command is run without specifying the source files or directories from which to extract translatable messages.
fixProvide 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=.`.
RuntimeError: The babel data files are not available.
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.
fixIf 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.
ModuleNotFoundError: No module named 'babel.numbers'
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.
fixExplicitly 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.
Upgrade
Version history
2.18.0latest on PyPI · released Feb 1, 2026
Audit
Dependencies
pytzrequiredProvides timezone definitions for date and time formatting
sixoptionalEnsures compatibility between Python 2 and 3