32

I have been trying to install musicbrainz server on my mac and there is a step where I have to install pip pyicu. I keep getting this error:

Collecting pyicu
Downloading PyICU-1.9.5.tar.gz (181kB)
100% |████████████████████████████████| 184kB 515kB/s 
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/pip-build-E50o2C/pyicu/setup.py", line 11, in <module>
    ICU_VERSION = subprocess.check_output(('icu-config', '--version')).strip()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-E50o2C/pyicu/

I have tried downloading ez_setup.py and doing python ez_setup.py. I have upgraded the setuptools and downloaded those separately as well. I am not sure what else there is to try. Please help!

Eric Agredo
  • 487
  • 1
  • 4
  • 13
  • The musicbrainz server is written in Perl, which part of it makes you try installing pyicu? – Wieland Dec 04 '16 at 19:37
  • I keep getting this error : fatal error: 'unicode/utypes.h' file not found after trying the make command. After that I try pip install polyglot, but then I get Command "python setup.py egg_info" failed with error code 1. I just need to solve the first error, but I have tried many options and I believe pyicu was an attempt at that. – Eric Agredo Dec 06 '16 at 03:38
  • Running this in the command line: `export PYICU_CFLAGS=-std=c++11:-DPYICU_VER='"2.0.3"'` worked for me. – Siddharth Das May 08 '18 at 09:38

9 Answers9

45

I faced this issue on ubuntu 14.04 and 16.04. To fix this issue, install libicu-dev then try installing again. I did

$sudo apt install libicu-dev
$pip install pyicu
Grant Foster
  • 722
  • 2
  • 11
  • 21
MUNGAI NJOROGE
  • 1,144
  • 1
  • 12
  • 25
21

I was facing this issue on my mac when trying to install polyglot (pyicu is needed for polyglot). The following resolved this for me.

# Install icu
brew install icu4c

# check newest version
ls /usr/local/Cellar/icu4c/

# Edit pyicu installer to work
git clone https://github.com/ovalhub/pyicu.git

# edit setup.py not to query for the version, i.e. change
# ICU_VERSION = subprocess.check_output(('icu-config', '--version')).strip()
# to whatever your version is, e.g.
# ICU_VERSION = '57.1'

# Install pyicu
env LDFLAGS=-L/usr/local/opt/icu4c/lib CPPFLAGS=-I/usr/local/opt/icu4c/include DYLD_LIBRARY_PATH=-L/usr/local/opt/icu4c/lib python setup.py build
env LDFLAGS=-L/usr/local/opt/icu4c/lib CPPFLAGS=-I/usr/local/opt/icu4c/include DYLD_LIBRARY_PATH=-L/usr/local/opt/icu4c/lib sudo python setup.py install

# Change DYLD_LIBRARY_PATH (not sure if req'd)
DYLD_LIBRARY_PATH=/usr/local/Cellar/icu4c/{version, e.g. 57.1}/:$DYLD_LIBRARY_PATH
echo $DYLD_LIBRARY_PATH

# Icu works now from python, and you can proceed with polyglot
$ python
>>> import icu
$ pip install polyglot
$ python
>>> import polyglot
Schultz9999
  • 8,717
  • 8
  • 48
  • 87
ppt
  • 946
  • 8
  • 18
21

for me to get it works:

1) install icu4c with brew:

brew install icu4c
brew link icu4c --force

2) check the version:

ls /usr/local/Cellar/icu4c/

it prompts something like: 64.2

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=64
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/64.2/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/64.2/lib

4) finally install python package for pyicu:

pip install pyicu --upgrade

IF YOU FAIL with above (happen already to me on OS X 10.15) you may need:

brew install pkg-config

export PYICU_CFLAGS=-std=c++11:-DPYICU_VER='"2.3.1"'
andilabs
  • 22,159
  • 14
  • 114
  • 151
12

On macOS 10.14.2 simply adding the directory containing icu-config to the PATH did the trick for me:

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

In fact, this is suggested by brew info icu4c:

==> Caveats
icu4c 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 icu4c 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 icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
8

Below solution is for MAC OSX only-

try installing pyICU using brew:

brew install icu4c

if it says that it's already installed and just need to be linked, then try this:

brew link icu4c

This create relative symlinks in "/usr/local/Cellar/icu4c/..."

coderjack
  • 666
  • 6
  • 4
  • 2
    Thanks, what worked for me was: `brew link --force icu4c` then install pyICU, then `brew unlink icu4c` to avoid conflicts while building software that depends on mac's lib version. – andreskwan Sep 17 '17 at 13:09
  • mac os 10.13.6 : "brew install icu4c" then "brew link --force icu4c" worked for me – Adil Oct 02 '18 at 08:54
7

Following solution worked for me on OSX:

# Install ucu4c via Brew
brew install icu4c

# Create relative symlinks for icu4c
brew link --force icu4c

# Install pyicu via pip
# Make sure ICU_VERSION matches the one you just installed
sudo ICU_VERSION=60.2 pip install pyicu
  • +1 this actually works in Sierra for me as well. Even force linking with brew didn't work - explicitly telling which version to choose did! Thanks. – koressak Feb 20 '18 at 07:55
1

It seems like the current version of icu4c packaged for brew does not link the icu-config file properly.

Running brew link icu4c --force gives you the necessary information to address this, but fails to link it automatically.

$ brew link --force icu4c
Warning: Refusing to link macOS-provided software: icu4c
If you need to have icu4c first in your PATH run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

For pkg-config to find icu4c you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

You need to run the following after installing icu4c through brew to get icu-config into your path (assuming you're running bash as your shell):

echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

After that, you should be able to install pyicu without any additional environment variables:

$ pip install --no-cache-dir pyicu
Collecting pyicu
  Downloading https://files.pythonhosted.org/packages/c2/15/0af20b540c828943b6ffea5677c86e908dcac108813b522adebb75c827c1/PyICU-2.2.tar.gz (211kB)
    100% |████████████████████████████████| 215kB 4.9MB/s 
Installing collected packages: pyicu
  Running setup.py install for pyicu ... done
Successfully installed pyicu-2.2

In summary, here's a complete list of commands i ran to make this work:

brew install icu4c
brew link icu4c --force
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
pip install --no-cache-dir pyicu

(As an aside, many of the solutions i came across do not use the --no-cache-dir option with pip install. I think some of them may have cached built version of pyicu. I did for a while, which masked the issue. It wasn't until i tried this option that i was able to reproduce and fix appropriately.)

Nicholas Tulach
  • 1,023
  • 3
  • 12
  • 35
1

This fails because icu4c is a keg-only formula as you can see in the Caveats section of brew info icu4c.

Some other answer recommend to use brew link icu4c but that may cause other issues as macOS already provides libicucore.dylib.

pip install pyicu fails because

  • will try run icu-config command, so icu-config must be in the PATH
  • will try to run pkgconfig ... icu-i18n so the .pc files for icu4c must be in the PKG_CONFIG_PATH

For macOS if you don't want to brew link icu4c and just want to make icu4c available to your pip install command then you can do this instead:

brew install pkg-config icu4c

# brew info icu4c 
export PATH="/usr/local/opt/icu4c/bin:$PATH"
export PATH="/usr/local/opt/icu4c/sbin:$PATH"
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"

icu-config --version # 68.2
pkg-config --modversion icu-i18n # 68.2

pip install pyicu==2.6.0 # works because icu-config in PATH and pkgconfig can find icu4c
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
0

I was trying to install in RHEL and I installed from the tar.gz file. Below are the commands:

    /usr/local/bin/pip3 install -U setuptools
    /usr/local/bin/pip3 install -U wheel
    wget http://download.icu-project.org/files/icu4c/50.1.2/icu4c-50_1_2-src.tgz
    tar -zxvf icu4c-50_1_2-src.tgz
    cd icu
    cd source
    sudo ./configure --prefix=/usr
    sudo make
    sudo make install
    icu-config --version
    /usr/local/bin/pip3 install PyICU==2.0.6
Chandan392
  • 59
  • 9