2

我已pyicu在 MacOS 和 Ubuntu 14.04 中安装,但在导入时显示 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
4

2 回答 2

11

在我的 Mac High Sierra 中构建和安装pyicu源代码时,我有同样的经历。

该错误消息Symbol not found: __ZNK6icu_6114Transliterator12getTargetSetERNS_10UnicodeSetE表明我们正在使用的 ICU 版本与构建包时实际使用的版本之间的共享库不匹配(Mac 具有内置的 ICU 库/usr/library/libicucore.dylib- 我怀疑在构建过程中将其用作默认值)。

因此,我执行了以下操作以使 pyicu 启动并使用正确的 icu 库运行:

  1. brew remove icu4c使用 homebrew (和brew install icu4c)删除并重新安装 icu4c

  2. ln -s /usr/local/Cellar/icu4c/61.1/bin/icu-config /usr/local/bin/icu-config在标准路径 ( )中创建 icu-config 符号链接

  3. 从 repo 克隆 pyicu,编辑文件并在, , ,部分setup.py下填写 'darwin' 的条目,如下所示:INCLUDESCFLAGSLFLAGSLIBRARIES

    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']
    }
    
  4. 构建和安装包,即python3 setup.py buildpython3 setup.py install

注意:如果您之前尝试(不成功)构建包,请确保build/在重新构建之前先清除目录的内容,因为如果构建过程看到目录填充了文件,则似乎跳过了新构建文件的创建从以前的构建。

于 2018-05-16T07:32:31.950 回答
-1

在针对 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'],
}

对于构建:

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
于 2019-04-29T14:23:03.477 回答