All posts

PyICU Installation on macOS

published on Saturday November 18, 2017 00:11:00

I was having difficulties installing PyICU on macOS. Normally, most packages I need can be installed by pip install <package_name> without any troubles or even better, sometimes they come with Anaconda. Sadly, I can't do that with PyICU and Anaconda.

What I've found so far

I followed the last link and got PyICU installed successfully.
I also tried to install it with Anaconda and here are the steps to install PyICU on macOS with Anaconda.

If you can't install with Anaconda, just follow the GitHub link above.

Step 1: Install icu4c using Homebrew

$ brew install icu4c

You will see the caveat like this:

    ==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have this software first in your PATH run:
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
LDFLAGS: -L/usr/local/opt/icu4c/lib
CPPFLAGS: -I/usr/local/opt/icu4c/include
For pkg-config to find this software you may need to set:
PKG_CONFIG_PATH: /usr/local/opt/icu4c/lib/pkgconfig

Step 2: Build and Install PyICU library from source

# Download PyICU-1.9.8.tar.gz from https://pypi.python.org/pypi/PyICU/
$ tar xvf PyICU-1.9.8.tar.gz
$ cd PyICU-1.9.8
$ LDFLAGS=-L/usr/local/opt/icu4c/lib CPPFLAGS=-I/usr/local/opt/icu4c/include python setup.py build
$ python setup.py install

Environment