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

aceminer
  • 4,089
  • 9
  • 56
  • 104

4 Answers4

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
Jessamyn Smith
  • 1,633
  • 13
  • 20
  • 2
    can you fix the name of the `icu` library it is `icu4c` not `icu4u` – Fabio Fumarola Feb 01 '16 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 '16 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.` – Daniel García Baena Jan 22 '19 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 '19 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= CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu – bormat Nov 26 '19 at 10:47
  • Im trying the steps above on macOs Catalina 10.15.4 and it doesn't work. brew link force complains about environment variables but even with those set as requested, it keeps returning the same warning – Daniel Vilas-Boas Apr 09 '20 at 01:58
19
brew install icu4c
brew link icu4c --force

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

xlm
  • 6,854
  • 14
  • 53
  • 55
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
andilabs
  • 22,159
  • 14
  • 114
  • 151
  • did you tried to import then the library like `python -c "import icu"? Because even if it installs, then you need extra setup to import `icu` correctly - see https://github.com/ovalhub/pyicu/issues/101 – loretoparisi Apr 30 '19 at 13:40
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.

Catalin P
  • 59
  • 8