我在MacOS和Ubuntu 14.04中都安装了pyicu
,但在导入时显示ImportError。
对于MacOS,高山脉输出是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/siddharthdas/venvs/chai/lib/python3.6/site-packages/icu/__init__.py", line 37, in <module>
from _icu import *
ImportError: dlopen(/Users/siddharthdas/venvs/chai/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so, 2): Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE
Referenced from: /Users/siddharthdas/venvs/chai/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so
Expected in: flat namespace
in /Users/siddharthdas/venvs/chai/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so
并在ubuntu 14.0上:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hackathon/venvs/grey_worm/lib/python3.4/site-packages/icu/__init__.py", line 37, in <module>
from _icu import *
ImportError: libicui18n.so.58: cannot open shared object file: No such file or directory
答案 0 :(得分:7)
在我的Mac High Sierra中从源代码构建和安装pyicu
时,我有相同的经验。
错误消息Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE
表示我们正在使用的ICU版本与构建软件包时实际使用的ICU版本之间的共享库不匹配(Mac在/usr/library/libicucore.dylib
中内置了ICU库 - 我怀疑在构建过程中被用作默认值。
所以,我做了以下操作以使pyicu启动并运行正确的icu lib:
使用自制程序(brew remove icu4c
和brew install icu4c
)
在标准路径(ln -s /usr/local/Cellar/icu4c/61.1/bin/icu-config /usr/local/bin/icu-config
)中创建icu-config符号链接
从repo克隆pyicu,编辑setup.py
文件,并在INCLUDES
,CFLAGS
,LFLAGS
,{{下填写'darwin'条目1}}部分如下:
LIBRARIES
构建并安装软件包,即INCLUDES = {
'darwin': ['/usr/local/Cellar/icu4c/61.1/include']
}
CFLAGS = {
'darwin': ['-DPYICU_VER="%s"' %(VERSION), '-std=c++11']
}
LFLAGS = {
'darwin': ['-L/usr/local/Cellar/icu4c/61.1/lib']
}
LIBRARIES = {
'darwin': ['/usr/local/Cellar/icu4c/61.1/lib']
}
和python3 setup.py build
注意:如果您以前尝试过(不成功)构建程序包,请确保在重建之前先清除python3 setup.py install
目录的内容,因为构建过程似乎跳过了新构建文件的创建如果它看到填充了以前版本的文件的目录。
答案 1 :(得分:0)
如上所述,当我在pycu
中针对python2.7在macOS(64.2)上安装setup.py
最新版本时:
INCLUDES = {
'darwin': ['/usr/local/Cellar/icu4c/64.2'],
'linux': [],
'freebsd': ['/usr/local/include'],
'win32': ['c:/icu/include'],
'sunos5': [],
'cygwin': [],
}
CFLAGS = {
'darwin': ['-DPYICU_VER="%s"' %(VERSION), '-std=c++11'],
'linux': [],
'freebsd': ['-std=c++11'],
'win32': ['/Zc:wchar_t', '/EHsc'],
'sunos5': ['-std=c++11'],
'cygwin': ['-D_GNU_SOURCE=1', '-std=c++11'],
}
LFLAGS = {
'darwin': ['-L/usr/local/Cellar/icu4c/64.2/lib'],
'linux': [],
'freebsd': ['-L/usr/local/lib'],
'win32': ['/LIBPATH:c:/icu/lib'],
'sunos5': [],
'cygwin': [],
}
LIBRARIES = {
'darwin': ['/usr/local/Cellar/icu4c/64.2/lib'],
'linux': [],
'freebsd': ['icui18n', 'icuuc', 'icudata'],
'win32': ['icuin', 'icuuc', 'icudt'],
'sunos5': ['icui18n', 'icuuc', 'icudata'],
'cygwin': ['icui18n', 'icuuc', 'icudata'],
}
并进行构建:
CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib python setup.py build
python setup.py install
然后我安装了PyICU 2.3.1
:
Installed /usr/local/lib/python2.7/site-packages/PyICU-2.3.1-py2.7-macosx-10.14-x86_64.egg
Processing dependencies for PyICU==2.3.1
Finished processing dependencies for PyICU==2.3.1