PyICU is a Python extension that wraps the International Components for Unicode (ICU) C++ libraries. It provides robust, full-featured Unicode and globalization support for applications, handling tasks such as locale-aware text formatting, collation, character set conversions, and boundary analysis. The current version is 2.16.2, and the library maintains an active release cadence, often aligning with updates to the underlying ICU C++ library.
pip install pyicuVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `Locale` object to get a locale's display name and how to use `BreakIterator` for locale-aware text segmentation into grapheme clusters. PyICU exposes much of the underlying ICU C++ API directly.
Ensure ICU C++ libraries are installed via your system's package manager (e.g., `brew install icu4c`, `sudo apt-get install libicu-dev`) and that `pkg-config` can locate them or relevant environment variables are set.
Consult the official ICU4C API reference (e.g., `https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/`) and infer the Python equivalents. Common patterns for string and date conversions are described in the PyICU README.
Be aware of whether an ICU function expects an output `UnicodeString` to be modified in place or returns a new string. For non-UTF-8 encoded Python `str`, explicitly construct `UnicodeString(str, encodingName)`.
Ensure your CFLAGS include the appropriate C++ standard flag (`-std=c++11` or `-std=c++17`) when building PyICU from source, or use pre-built binaries if available for your environment.
Ensure `pkg-config` is installed and configured to find your ICU libraries. Verify with `pkg-config --cflags --libs icu-i18n`.
Install `pkg-config` and the ICU development libraries using your operating system's package manager (e.g., `sudo apt-get install libicu-dev pkg-config` on Debian/Ubuntu, or `brew install icu4c pkg-config` on macOS).
Ensure PyICU is properly installed by running `pip install pyicu` in the active Python environment. If prior installation issues existed, verify that the underlying ICU C++ libraries were correctly installed before reinstalling PyICU.
Ensure that the ICU C++ library version used for building PyICU matches the one available at runtime. This typically involves reinstalling `icu4c` (e.g., `brew install icu4c` on macOS) and then reinstalling PyICU, often by setting explicit environment variables like `export LDFLAGS="-L$(brew --prefix)/opt/icu4c/lib" export CPPFLAGS="-I$(brew --prefix)/opt/icu4c/include"` before running `pip install pyicu`.
First, ensure `pyicu` is the intended `icu` module by checking installed packages. If there are conflicts, try uninstalling other packages named 'icu' or 'PyICU'. Then, perform a clean reinstall of PyICU (`pip uninstall pyicu && pip install pyicu`) after verifying that system ICU dependencies are correctly installed.