4

I'm trying to install pyicu for python 3.5 on mac according to this link https://struggley.wordpress.com/2015/07/14/installation-pyicu-on-mac-osx-yosemite/

However, when I excute pip3 install pyicu, I got this error

Collecting pyicu
Using cached PyICU-1.9.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/70/jlxmpp0n003805pmw6tfc0r80000gn/T/pip-build-7eusuic1/pyicu/setup.py", line 11, in <module>
    ICU_VERSION = subprocess.check_output(('icu-config', '--version')).strip()
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 693, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'icu-config'

I guess it's because I didn't set the path for icu-config correctly. I think the following two may be the icu-config files.

/usr/local/Cellar/icu4c/58.1/bin/icu-config
/usr/local/Cellar/icu4c/58.1/share/man/man1/icu-config.1

However, I have no idea how to set the path to it. Besides, I don't know why I got this error while the tutorial can work smoothly.

Chenlu
  • 449
  • 1
  • 6
  • 19
  • Possible duplicate of [Error installing pip pyicu](https://stackoverflow.com/questions/40940188/error-installing-pip-pyicu) – RobC Feb 13 '19 at 15:10

2 Answers2

20

I had the same problem. This worked for me

brew install intltool icu4c gettext
brew link icu4c gettext --force
CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip3 install pyicu

Source: https://github.com/Homebrew/legacy-homebrew/issues/34170

dimid
  • 7,285
  • 1
  • 46
  • 85
  • 1
    Cool! I didn't have gettext installed before. But after I brew install gettext, your method works magically. Thank you. – Chenlu Dec 13 '16 at 15:53
  • BTW, since I'm using Anaconda python 3.5, I'm using pip install, not pip3 install. – Chenlu Dec 13 '16 at 16:18
  • 4
    The solution works, although I had to do the following as well. 1) Add /usr/local/opt/icu4c/bin to PATH 2) Set ICU_VERSION – Douglas Liu Nov 07 '18 at 07:04
11

Simply add the directory containing icu-config to the PATH, e.g.:

brew install icu4c
export PATH="/usr/local/opt/icu4c/bin:$PATH"
pip install pyicu

If you use pipenv, you could also update PATH via a .env file. In your project root directory, create a file named .env with the following content:

PATH="/usr/local/opt/icu4c/bin:${PATH}"

Then run:

pipenv shell
pipenv install pyicu
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378