python-3.x - 正确安装 PyICU 和 icu4c 时,多语言导入或未找到符号错误
问题描述
我真的很挣扎polyglot
,pyicu
而且icu4c
- 似乎我不是唯一一个......
我正在10.13.6
使用 virtualenv 运行 Mac OS High Sierra 和 python3
以下是我采取的步骤,主要基于这篇文章:
- 从一个新的 virtualenv 开始
- 使用自制软件删除并重新安装 icu4c (v.62.1)
- 检查 ICU_VERSION 是否为“62.1”
- 做
ln -s /usr/local/Cellar/icu4c/62.1/bin/icu-config /usr/local/bin/icu-config
- 下载 pyicu tar 文件 (2.1)
- 如链接文章中所示,提取 pyicu 并编辑 setup.py
- 构建和安装 pyicu
我懂了:
Adding CXXFLAGS="-std=c++11 -I/usr/local/Cellar/icu4c/62.1/include" from /usr/local/bin/icu-config
Adding LDFLAGS="-L/usr/local/Cellar/icu4c/62.1/lib -licui18n -licuuc -licudata" from /usr/local/bin/icu-config
Installed/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PyICU-2.1-py3.6-macosx-10.6-intel.egg
...
Processing dependencies for PyICU==2.1
Finished processing dependencies for PyICU==2.1
正如预期的那样。
- pip3 安装多语言
当我运行我的脚本时,我得到以下信息:
File "/Users/Chris/MindWeb/Server/lib/python3.6/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/Users/Chris/MindWeb/Server/lib/python3.6/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
ModuleNotFoundError: No module named 'icu'
不足为奇,因为 PATH 中实际上没有 icu 模块。
如果,而不是步骤 5-7,我执行 pip3 install pyicu (创建 icu 文件夹),我得到:
ImportError: dlopen(/Users/Chris/MindWeb/Server/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so, 2): Symbol not found: __ZNK6icu_6214Transliterator12getTargetSetERNS_10UnicodeSetE
Referenced from: /Users/Chris/MindWeb/Server/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so
Expected in: flat namespace
in /Users/Chris/MindWeb/Server/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so
输出otool -L /Users/Chris/MindWeb/Server/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so
是:
/Users/Chris/MindWeb/Server/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so:
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
解决方案
Github 上的这个答案并不是专门针对这个错误,而是提供了一种使用 conda 和 Python 3.6 安装 polyglot 的简单方法(在解决了我遇到的其他人的 icu 错误之后,这很有帮助)。
https://github.com/aboSamoor/polyglot/issues/80#issuecomment-417863726
使用 conda env,您可以执行以下操作:
conda install -c conda-forge pyicu morfessor icu -y && pip install pycld2 polyglot
推荐阅读
- asp.net-mvc - DropDownListFor 未在修改的 Scaffold Razor 页面中返回选定值
- android - 在扩展方法中覆盖 onInterceptTouchEvent
- android - 添加firebase插件后,Nativescript应用程序不断在android上崩溃
- nginx - Nginx - 允许最大三级域
- r - 组合 ggplot2 对象时在拼凑中设置轴限制
- html - 通过模块共享的组件不会绑定 DOM 中的 HTML 属性
- c# - 如何根据表的最大标识键使用实体框架在 MVC 中保存数据时生成唯一编号?
- python - 用 Python 重命名文件夹中的所有文件
- mysql - SQLSTATE[HY000] [1045] 用户 'groot'@'localhost' 的访问被拒绝
- c# - 使用 QuickSort c# 按列对 CSV 文件进行排序