[英]Import error for icu in Mac and Ubuntu, although pyicu is installed correctly
I have pyicu
installed in both MacOS and Ubuntu 14.04 but it shows ImportError upon importing. 我在MacOS和Ubuntu 14.04中都安装了
pyicu
,但是在导入时会显示ImportError。 For MacOS high sierra output is: 对于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
and on ubuntu 14.0 this: 在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
I had the same experience when building and installing the pyicu
from source in my Mac High Sierra. 在Mac High Sierra中从源代码构建和安装
pyicu
时,我有相同的经验。
The error message Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE
is a sign of shared library mismatch between the ICU version we are using and the one actually used when building the package (Mac has built-in ICU library in /usr/library/libicucore.dylib
- which i suspect is used as default during build process). 错误消息
Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE
错误Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE
是我们使用的ICU版本与构建软件包时实际使用的ICU版本之间共享库不匹配的标志(Mac在/usr/library/libicucore.dylib
内置了ICU库-我怀疑在构建过程中将其用作默认设置)。
So, i did the following to get the pyicu up and running with the correct icu lib: 因此,我执行以下操作以使用正确的icu lib启动pyicu并运行它:
Remove and reinstall icu4c using homebrew ( brew remove icu4c
and brew install icu4c
) 使用自制软件删除并重新安装icu4c(
brew remove icu4c
并brew install icu4c
)
Create a icu-config symlink in standard path ( ln -s /usr/local/Cellar/icu4c/61.1/bin/icu-config /usr/local/bin/icu-config
) 在标准路径中创建一个icu-config符号链接(
ln -s /usr/local/Cellar/icu4c/61.1/bin/icu-config /usr/local/bin/icu-config
)
Clone the pyicu from repo, edit the setup.py
file and fill out the entries for 'darwin' under INCLUDES
, CFLAGS
, LFLAGS
, LIBRARIES
sections as follows: 从回购克隆pyicu,编辑
setup.py
文件,并填写“达尔文”下的条目INCLUDES
, CFLAGS
, LFLAGS
, 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'] }
Build and install the package, ie python3 setup.py build
and python3 setup.py install
编译并安装软件包,即
python3 setup.py build
和python3 setup.py install
Note: If you previously had tried (unsuccessfully) build the package, make sure that you clean out the content of the build/
dir first before rebuilding, as the build process seems to skip the creation of new build files if it sees the directory populated with files from previous build. 注意:如果您以前曾尝试(未成功)构建软件包,请确保在重建之前先清除
build/
目录的内容,因为如果编译过程看到目录已填充,则似乎会跳过创建新构建文件的过程与以前的版本中的文件。
When installing pycu
latest version on macOS (64.2) against python2.7 I did in setup.py
as described above: 当针对python2.7在macOS(64.2)上安装
pycu
最新版本时,我如上所述在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'],
}
and for the build: 对于构建:
CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib python setup.py build
python setup.py install
then I have got PyICU 2.3.1
installed: 然后我已经安装了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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.