Git Product home page Git Product logo

Comments (29)

workflowsguy avatar workflowsguy commented on August 17, 2024 24

The brew ICU package contains icu-config in /usr/local/Cellar/icu4c/60.2/bin/icu-config, which is not included in the standard path.

I have linked it into a standard path with ln -s /usr/local/Cellar/icu4c/60.2/bin/icu-config /usr/local/bin/icu-config.

Now, with sudo pip3 install pyicu, it finally builds successfully!

As icu-config is obviously a required precondition for building PyICU, it should not be assumed that it is found in the path. Instead, the PyICU setup script should check for it's presence and show an appropriate error message if not found.

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024 5

Either have your installation of ICU make the icu-config program available
or setup the env vars below according to your setup:

$ export ICU_VERSION=
$ export PYICU_INCLUDES=/include
$ export PYICU_LFLAGS=-L/lib
$ export PYICU_CFLAGS=-std=c++11

or edit setup.py and set INCLUDES, LFLAGS and CFLAGS accordingly.

from pyicu.

loretoparisi avatar loretoparisi commented on August 17, 2024 5

In my case I just did

export ICU_VERSION=63.1
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/63.1/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/63.1/lib
export PYICU_CFLAGS=-std=c++11
pip install pyicu

https://gist.github.com/loretoparisi/294b8f536750a18746fc6f43f7859928

the problem is when importing the library!

ip-192-168-22-157:~ loretoparisi$ python -c "import icu"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/icu/__init__.py", line 37, in <module>
    from _icu import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_icu.so, 2): Symbol not found: __ZN6icu_638ByteSink15GetAppendBufferEiiPciPi
  Referenced from: /usr/local/lib/python2.7/site-packages/_icu.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/_icu.so

from pyicu.

echo-phantom avatar echo-phantom commented on August 17, 2024 4

Nice bits of info a bit sparse/scattered. In summary what worked for future references:
I have MacOS 10.13. My project required PyICU-1.8 and the only icu4c that worked was version 57.1
$ brew remove icu4c
$ cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
$ git checkout 1e62c645b2fc2d82042d9f7c364c6a246f2e11ed Formula/icu4c.rb #this is the latest commit with 57.1
$ brew install icu4c
$ ln -s /usr/local/Cellar/icu4c/57.1/bin/icu-config /usr/local/bin/icu-config
My .bash_profile

 22 export ICU_VERSION=57.1
 23 export PYICU_INCLUDES=/usr/local/Cellar/icu4c/${ICU_VERSION}/include
 24 export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/${ICU_VERSION}/lib
 25 export PYICU_CFLAGS=-std=c++11:-DPYICU_VER='"1.8"'

$ source ~/.bash_profile && pip install PyICU==1.8 --ignore-installed

from pyicu.

akhudek avatar akhudek commented on August 17, 2024 3

It turns out that the right env var is:

export PYICU_CFLAGS=-std=c++11:-DPYICU_VER='"2.0.3"'

The : causes the arguments to be treated separately and the single quotes cause the double quotes to be included in the define.

from pyicu.

yu-imu avatar yu-imu commented on August 17, 2024 2

I also experienced this problem.

[Errno 2] No such file or directory: 'icu-config': 'icu-config'

I fixed as follow and finally installed pyicu
I already installed icu4c as follow
$ brew install icu4c
$ brew link icu4c
So, make to a path to .bash_profile
echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.bash_profile
echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
pip3 install pyicu

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024 1

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024 1

from pyicu.

antislice avatar antislice commented on August 17, 2024 1

I'm having the same series of issues that @workflowsguy had.

If I install with CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install pyicu, it installed successfully (this is all over the internet but mainly for ICU versions < 60 as far as I can tell). However, running my script that depends on pyicu (via polyglot) after that gives

Traceback (most recent call last):
  File "scrubber.py", line 14, in <module>
    from polyglot.text import Text
  File "/Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/polyglot/text.py", line 9, in <module>
    from polyglot.detect import Detector, Language
  File "/Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/polyglot/detect/__init__.py", line 1, in <module>
    from .base import Detector, Language
  File "/Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/polyglot/detect/base.py", line 11, in <module>
    from icu import Locale
  File "/Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/icu/__init__.py", line 37, in <module>
    from _icu import *
ImportError: dlopen(/Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/_icu.so, 2): Symbol not found: __ZNK6icu_6014Transliterator12getTargetSetERNS_10UnicodeSetE
  Referenced from: /Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/_icu.so
  Expected in: flat namespace
 in /Users/homeslice/work/scrubber/venv/lib/python2.7/site-packages/_icu.so

Which according to this stackoverflow question implies something was compiled incorrectly, so I tried the solutions offered above. And I'm at the same error: invalid suffix '.3' on floating constant error.

ICU_VERSION=60.2
PYICU_CFLAGS='-std=c++11 -DPYICU_VER=2.0.3'
PYICU_INCLUDES=/usr/local/opt/icu4c/include
PYICU_LFLAGS=-L/usr/local/opt/icu4c/lib

from pyicu.

will3216 avatar will3216 commented on August 17, 2024 1

This did the trick for me. No environment variables at all!

brew install intltool icu4c gettext
brew link icu4c gettext --force
pip3 install pyicu

from pyicu.

nmooman avatar nmooman commented on August 17, 2024 1

On Mac:
%brew install intltool icu4c gettext
%brew link icu4c gettext --force
%ls -arlt /usr/local/opt/icu4c/bin/icu-config
%git clone https://github.com/ovalhub/pyicu.git
%cd pyicu
check your icu4c version by
%ls /usr/local/Cellar/icu4c/
i.e., 59.1_1 61.1 62.1
%sudo ICU_VERSION='62.1' python3.6 setup.py build
%sudo ICU_VERSION='62.1' python3.6 setup.py install
%sudo pip3.6 install polyglot --upgrade

You might need if you encountered issues:
%export PYICU_INCLUDES=/include
%export PYICU_LFLAGS=-L/lib
%export PYICU_CFLAGS=-std=c++11

and in your setup.py
try:
ICU_VERSION = os.environ['ICU_VERSION']
#ICU_VERSION = '62.1'
except:
try:
#ICU_VERSION = check_output(('icu-config', '--version')).strip()
ICU_VERSION = '62.1'
if sys.version_info >= (3,):
ICU_VERSION = str(ICU_VERSION, 'ascii')
except:
raise RuntimeError('''
Please set the ICU_VERSION environment variable to the version of
ICU you have installed.
''')
Good luck.
Nasser

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024

builds fine for me both with Python 2 and 3.
How about a trace ?

from pyicu.

workflowsguy avatar workflowsguy commented on August 17, 2024

Thanks for listing the environment variables. However, PyICU still does not compile. This time, the error message is:

    Building PyICU 2.0.2 for ICU 60.2
    
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.11-x86_64-3.6
    copying PyICU.py -> build/lib.macosx-10.11-x86_64-3.6
    creating build/lib.macosx-10.11-x86_64-3.6/icu
    copying icu/__init__.py -> build/lib.macosx-10.11-x86_64-3.6/icu
    running build_ext
    building '_icu' extension
    creating build/temp.macosx-10.11-x86_64-3.6
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/opt/icu4c/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _icu.cpp -o build/temp.macosx-10.11-x86_64-3.6/_icu.o -std=c++11
    _icu.cpp:206:31: error: use of undeclared identifier 'PYICU_VER'
        ver = PyString_FromString(PYICU_VER);
                                  ^
    1 error generated.
    error: command 'clang' failed with exit status 1

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024

from pyicu.

workflowsguy avatar workflowsguy commented on August 17, 2024

OK, I initiate the build process with

CFLAGS=-D PYICU_VER=2.0.2 pip3 install pyicu

Now the next errors I get are those:

    Building PyICU 2.0.2 for ICU 60.2
    
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.11-x86_64-3.6
    copying PyICU.py -> build/lib.macosx-10.11-x86_64-3.6
    creating build/lib.macosx-10.11-x86_64-3.6/icu
    copying icu/__init__.py -> build/lib.macosx-10.11-x86_64-3.6/icu
    running build_ext
    building '_icu' extension
    creating build/temp.macosx-10.11-x86_64-3.6
    clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -D -I/usr/local/opt/icu4c/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _icu.cpp -o build/temp.macosx-10.11-x86_64-3.6/_icu.o -std=c++11
    In file included from <built-in>:356:
    <command line>:2:9: error: macro name must be an identifier
    #define -I/usr/local/opt/icu4c/include 1
            ^
    In file included from _icu.cpp:27:
    ./common.h:105:10: fatal error: 'unicode/utypes.h' file not found
    #include <unicode/utypes.h>
             ^
    2 errors generated.
    error: command 'clang' failed with exit status 1
    

from pyicu.

workflowsguy avatar workflowsguy commented on August 17, 2024

When running CFLAGS=-DPYICU_VER=2.0.2 pip3 install pyicu, I get

Collecting pyicu
  Using cached PyICU-2.0.2.tar.gz
Building wheels for collected packages: pyicu
  Running setup.py bdist_wheel for pyicu ... error
  Complete output from command /usr/local/opt/python3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/59/18ktbnzd1nq82_537cj3lmj40000gn/T/pip-build-8qbqoukc/pyicu/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/59/18ktbnzd1nq82_537cj3lmj40000gn/T/tmpfipy6ld_pip-wheel- --python-tag cp36:
  
  Building PyICU 2.0.2 for ICU 60.2
  
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.11-x86_64-3.6
  copying PyICU.py -> build/lib.macosx-10.11-x86_64-3.6
  creating build/lib.macosx-10.11-x86_64-3.6/icu
  copying icu/__init__.py -> build/lib.macosx-10.11-x86_64-3.6/icu
  running build_ext
  building '_icu' extension
  creating build/temp.macosx-10.11-x86_64-3.6
  clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DPYICU_VER=2.0.2 -I/usr/local/opt/icu4c/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _icu.cpp -o build/temp.macosx-10.11-x86_64-3.6/_icu.o -std=c++11
  _icu.cpp:206:31: error: invalid suffix '.2' on floating constant
      ver = PyString_FromString(PYICU_VER);
                                ^
  <command line>:2:22: note: expanded from here
  #define PYICU_VER 2.0.2
                       ^
  1 error generated.
  error: command 'clang' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for pyicu
  Running setup.py clean for pyicu
Failed to build pyicu
Installing collected packages: pyicu
  Running setup.py install for pyicu ... error
    Complete output from command /usr/local/opt/python3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/59/18ktbnzd1nq82_537cj3lmj40000gn/T/pip-build-8qbqoukc/pyicu/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/59/18ktbnzd1nq82_537cj3lmj40000gn/T/pip-ntkw1gw_-record/install-record.txt --single-version-externally-managed --compile:
    
    Building PyICU 2.0.2 for ICU 60.2
    
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.11-x86_64-3.6
    copying PyICU.py -> build/lib.macosx-10.11-x86_64-3.6
    creating build/lib.macosx-10.11-x86_64-3.6/icu
    copying icu/__init__.py -> build/lib.macosx-10.11-x86_64-3.6/icu
    running build_ext
    building '_icu' extension
    creating build/temp.macosx-10.11-x86_64-3.6
    clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DPYICU_VER=2.0.2 -I/usr/local/opt/icu4c/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _icu.cpp -o build/temp.macosx-10.11-x86_64-3.6/_icu.o -std=c++11
    _icu.cpp:206:31: error: invalid suffix '.2' on floating constant
        ver = PyString_FromString(PYICU_VER);
                                  ^
    <command line>:2:22: note: expanded from here
    #define PYICU_VER 2.0.2
                         ^
    1 error generated.
    error: command 'clang' failed with exit status 1

I do not understand what you mean by

But if you must, use PYICU_CFLAGS instead.

If I enter export PYICU_CFLAGS="-std=c++11 -DPYICU_VER=2.0.2" and then pip3 install pyicu, I get an error error: invalid value 'c++11 -DPYICU_VER=2.0.2' in '-std=c++11 -DPYICU_VER=2.0.2

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024

from pyicu.

workflowsguy avatar workflowsguy commented on August 17, 2024

Regardless of whether I enter
CFLAGS='-DPYICU_VER="2.0.2"' pip3 install pyicu or just pip3 install pyicu,

PYICU simply does not build, giving different error messages based on the command entered, as mentioned above.

The environment variables are set as per your answers:

ICU_VERSION=60.2
PYICU_CFLAGS=-std=c++11
PYICU_INCLUDES=/usr/local/opt/icu4c/include
PYICU_LFLAGS=-L/usr/local/opt/icu4c/lib

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024

from pyicu.

ovalhub avatar ovalhub commented on August 17, 2024

from pyicu.

wachmann avatar wachmann commented on August 17, 2024

Don’t use a space character after -D: CFLAGS=-DPYICU_VER=2.0.2 You shouldn’t have to set this, by the way... But if you must, use PYICU_CFLAGS instead.

Thanks! This worked for me!

from pyicu.

Hultner avatar Hultner commented on August 17, 2024

@will3216 I'm not able to get it to work with your solution, the only way for me to install it is to set up the path or link icu-config manually.

I can get it to install successfully on my machine with some hassle but it's hard for me to be able to create a reproducible setup.py so that other developers in my team are able to install the package without to much hassle.

Brew won't let me force link icu4c and gives the following output if I try.

$ brew link 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"' >> ~/.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"

from pyicu.

will3216 avatar will3216 commented on August 17, 2024

@Hultner did you install icu4c with brew? It seems like that warning is indicating it was installed directly on your OS. This has become a requirement for each person on our team that needs to load our ecosystem and the solution provided above worked for each of us thus far. That said, your setup could easily be different in some way. What version of macOS are running?

from pyicu.

Hultner avatar Hultner commented on August 17, 2024

@will3216 Yep, I installed it through brew. I've never knowingly installed it directly through my OS. It might have been installed previously by some other software, may it be bundled with xcode or similar?

from pyicu.

will3216 avatar will3216 commented on August 17, 2024

@Hultner I'm not sure then. What I do know is that the command you listed above was brew link icu4c not brew link icu4c --force. If that doesn't work, I'd recommend going with @DiegoCoder's solution (being sure to change the ICU_VERSION to whatever version you have installed).

from pyicu.

Hultner avatar Hultner commented on August 17, 2024

@will3216 I tried both with the same result. I did get it to work when setting up the path manually and defining ICU_VERSION in my environment before running pipenv install on the project. It's just a bit more cumbersome for our developers this way since we need to set up new PATH variables etc.

from pyicu.

will3216 avatar will3216 commented on August 17, 2024

@Hultner Yeah, that approach is definitely a bit cumbersome and easy to forget down the line when you onboard new team members, but I suspect that the issue you are running into might be specific to your particular environment. It may be possible for other members of your team to use the brew link force approach (unless of course the issue is derived from a tool your whole team uses)

from pyicu.

wilfredcho avatar wilfredcho commented on August 17, 2024

@loretoparisi Were you able to resolve this problem? I just ran into it.

from pyicu.

piyiotisk avatar piyiotisk commented on August 17, 2024

In my case I just did

export ICU_VERSION=63.1
export PYICU_INCLUDES=/usr/local/Cellar/icu4c/63.1/include
export PYICU_LFLAGS=-L/usr/local/Cellar/icu4c/63.1/lib
export PYICU_CFLAGS=-std=c++11
pip install pyicu

https://gist.github.com/loretoparisi/294b8f536750a18746fc6f43f7859928

the problem is when importing the library!

ip-192-168-22-157:~ loretoparisi$ python -c "import icu"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/icu/__init__.py", line 37, in <module>
    from _icu import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/_icu.so, 2): Symbol not found: __ZN6icu_638ByteSink15GetAppendBufferEiiPciPi
  Referenced from: /usr/local/lib/python2.7/site-packages/_icu.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/_icu.so

Yes, I was able to resolve this. Basically, reading this guide https://docs.brew.sh/Homebrew-and-Python you will need to run CFLAGS=-I$(brew --prefix)/include LDFLAGS=-L$(brew --prefix)/lib pip install pyicu` without using a virtualenv. This will pass the correct compiler parameters so the brew icu4c could communicate with the python lib. After that enable the virtualenv and you will be good to go

from pyicu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.