{"id":428,"library":"babel","title":"Babel: Internationalization Utilities for Python","description":"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.","status":"active","version":"2.18.0","language":"python","source_language":"en","source_url":"https://github.com/python-babel/babel","tags":["internationalization","localization","Python","date formatting","time formatting"],"install":[{"cmd":"pip install babel","lang":"bash","label":"Install Babel"}],"dependencies":[{"reason":"Provides timezone definitions for date and time formatting","package":"pytz","optional":false},{"reason":"Ensures compatibility between Python 2 and 3","package":"six","optional":true}],"imports":[{"note":"Ensure correct import path to access date formatting functions","symbol":"format_date","correct":"from babel.dates import format_date"}],"quickstart":{"code":"from babel import Locale\n\n# Set the locale to French\nlocale = Locale('fr', 'FR')\n\n# Format a date in the French locale\nfrom babel.dates import format_date\nfrom datetime import datetime\n\ndate = datetime(2026, 3, 28)\nformatted_date = format_date(date, locale=locale)\nprint(formatted_date)  # Output: 28 mars 2026","lang":"python","description":"This example demonstrates how to set a locale and format a date accordingly using Babel."},"warnings":[{"fix":"Upgrade to Python 3.8 or later to maintain compatibility.","message":"Babel 2.15.0 dropped support for Python 3.7, requiring Python 3.8 or newer.","severity":"breaking","affected_versions":"2.15.0"},{"fix":"Use 'format_date' or 'format_time' as appropriate for your use case.","message":"The 'format_datetime' function is deprecated and will be removed in a future release.","severity":"deprecated","affected_versions":"2.18.0"}],"env_vars":null,"last_verified":"2026-05-12T13:44:25.742Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"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.","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.","error":"ModuleNotFoundError: No module named 'babel'"},{"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)`.","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.","error":"AttributeError: 'Babel' object has no attribute 'localeselector'"},{"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=.`.","cause":"This error occurs when the `pybabel extract` command is run without specifying the source files or directories from which to extract translatable messages.","error":"pybabel: error: no input files or directories specified"},{"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.","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.","error":"RuntimeError: The babel data files are not available."},{"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.","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.","error":"ModuleNotFoundError: No module named 'babel.numbers'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.9,"disk_size":"50.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.9,"disk_size":"51M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":2.1,"disk_size":"52.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2.1,"disk_size":"53M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2,"disk_size":"44.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":2,"disk_size":"45M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.9,"disk_size":"44.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"45M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.8,"disk_size":"50.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.8,"disk_size":"51M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}