17

how do i install libicu-dev on mac. This is the instruction recommended on the documentation

sudo apt-get install python-numpy libicu-dev

http://polyglot.readthedocs.org/en/latest/Installation.html

I am using anaconda but it seems to always throw up an

In file included from _icu.cpp:27:
    ./common.h:86:10: fatal error: 'unicode/utypes.h' file not found
    #include <unicode/utypes.h>

error

4 Answers 4

30

I just got PyICU to install on OSX, after it was failing due to that same error. Here is what I recommend:

  1. Install homebrew (package manager for OSX)
  2. brew install icu4c # Install the library; may be already installed
  3. Verify that the necessary include directory is present: ls -l /usr/local/opt/icu4c/include/
  4. If you do not have that directory, you may need to reinstall icu4u. I found that I had to do the following:
    1. brew remove icu4c
    2. brew install icu4c
  5. Try to install polyglot to see if it can find icu4c: pip install polyglot
  6. If that still complains, you can try specifying library location: CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install polyglot

EDIT: There have been further changes. My current process for installing icu:

  1. brew install icu4c
  2. brew link icu4c --force
  3. ICU_VERSION=<BREW_ICU_VERSION> CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu
6
  • 2
    can you fix the name of the icu library it is icu4c not icu4u Feb 1, 2016 at 20:34
  • Your answer is a bit hard to follow. Would be nice if you could explain the purpose of each step ,especially the last two.
    – fraxture
    Aug 30, 2016 at 11:12
  • I'm always getting the same error: RuntimeError: Please set the ICU_VERSION environment variable to the version of ICU you have installed. Jan 22, 2019 at 20:36
  • 1
    I had to also follow the brew suggestion and export both icu4c to my bash profile (zsh in this case) ` echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc`
    – james-see
    Feb 23, 2019 at 13:17
  • for me the installation succeed but failed during the import I had to uninstall pyicu before to reinstall it with ICU_VERSION=<BREW_ICU_VERSION> CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu
    – bormat
    Nov 26, 2019 at 10:47
19
brew install icu4c
brew link icu4c --force

https://github.com/imojiengineering/node-icu-tokenizer

3
  • 2
    This was the only answer that did the work. Thank you!
    – nova
    Jun 15, 2017 at 13:18
  • for me brew link icu4c --force is necessary to work correctly on Max OSx 10.11.6 - python 2.7 Nov 23, 2017 at 12:20
  • I get Warning: Refusing to link macOS provided/shadowed software: icu4c Mar 21, 2022 at 14:42
1

for me the simple answer with just brew install and linking does not work so I found the below solution to make it works:

1) install icu4c with brew:

brew install icu4c

2) check the version:

ls /usr/local/Cellar/icu4c/

it prompts something like: 59.1

3) execute bellow commands with substitution of proper version from previous step (first line only integer part, second and third line with decimal part):

export ICU_VERSION=59
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/59.1/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/59.1/lib

4) finally install python package for pyicu:

pip install pyicu
1
0

Mac OS 13.4, Python 3.8 (Xcode), icu4c 72.1

I first tried Jessamyn's answer (https://stackoverflow.com/a/33352241/2793863), with ICU_VERSION=<BREW_ICU_VERSION> CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu, it built but failed at runtime:

ImportError: dlopen(/Users/catalinp/Library/Python/3.8/lib/python/site-packages/icu/_icu_.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '__ZN6icu_7218AnnualTimeZoneRule8MAX_YEARE'

The following worked for me:

PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig pip3 install pyicu

Note, in practice, I also had --force-reinstall --ignore-installed --no-binary :all: to force pip to rebuild.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.