![](/img/trans.png)
[英]Import error for icu in Mac and Ubuntu, although pyicu is installed correctly
[英]Import or Symbol not Found Error with polyglot when PyICU and icu4c installed correctly
我真的在為polyglot
、 pyicu
和icu4c
苦苦掙扎——而且似乎我不是唯一一個......
我正在使用 virtualenv 運行 Mac OS High Sierra 10.13.6
和 python3
以下是我采取的步驟,主要基於這篇文章:
ln -s /usr/local/Cellar/icu4c/62.1/bin/icu-config /usr/local/bin/icu-config
我懂了:
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
正如預期的那樣。
當我運行我的腳本時,我得到以下信息:
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 模塊。
如果我執行 pip3 install pyicu (創建 icu 文件夾)而不是步驟 5-7,我會得到:
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 安裝多語言的簡單方法(在解決了 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.