Reputation: 121
I was trying to run the polyglot for my sentimental analysis. After a lot of struggling,, I successfully installed Polyglot and pyicu. However when I ran my program, it gave me this error, and I don't know how to fix it
Traceback (most recent call last):
File "/Users/siyizhou/Documents/2020Fall/COMMresearch/code2/Pos_Neg.py", line 6, in <module>
from polyglot.text import Text
File "/usr/local/lib/python3.9/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "/usr/local/lib/python3.9/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/usr/local/lib/python3.9/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
ImportError: cannot import name 'Locale' from 'icu' (/usr/local/lib/python3.9/site-
packages/icu/__init__.py)
siyizhou@Siyis-MBP code2 % polyglot download sentiment.en
Traceback (most recent call last):
File "/usr/local/bin/polyglot", line 33, in <module>
sys.exit(load_entry_point('polyglot==16.7.4', 'console_scripts', 'polyglot')())
File "/usr/local/bin/polyglot", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/polyglot/__main__.py", line 16, in <module> from icu import Locale
ImportError: cannot import name 'Locale' from 'icu' (/usr/local/Cellar/[email protected]/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/icu/__init__.py)
Upvotes: 12
Views: 11486
Reputation: 51
If you are on MacOSX with a version around 13 (M1 or other), you may need some extra steps beforehand to update the search paths:
Start by installing pkg-config
and icu4c
, necessary for pyicu
to work:
brew install pkg-config icu4c
Next, get the correct path to icu4c
with the following command:
brew info icu4c
You will get an output like this:
==> icu4c: stable 71.1 (bottled) [keg-only] C/C++ and Java libraries for Unicode and globalization https://icu.unicode.org/home /opt/homebrew/Cellar/icu4c/71.1 (262 files, 76.8MB) Poured from bottle on 2023-01-02 at 16:21:11 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/icu4c.rb License: ICU ==> Caveats icu4c is keg-only, which means it was not symlinked into /opt/homebrew, because macOS provides libicucore.dylib (but nothing else).
If you need to have icu4c first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/icu4c/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/icu4c/sbin:$PATH"' >> ~/.zshrc
For compilers to find icu4c you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/icu4c/lib"
export CPPFLAGS="-I/opt/homebrew/opt/icu4c/include"
For pkg-config to find icu4c you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig"
==> Analytics install: 375,450 (30 days), 1,501,837 (90 days), 5,475,904 (365 days) install-on-request: 6,461 (30 days), 20,819 (90 days), 87,520 (365 days) build-error: 15 (30 days)
Look at the export
sections, in this case, my path to icu4c
is: /opt/homebrew/opt/icu4c/
Use this path you got to update the following commands:
export PATH="/opt/homebrew/opt/icu4c/bin:/opt/homebrew/opt/icu4c/sbin:$PATH"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/homebrew/opt/icu4c/lib/pkgconfig"
export PYICU_INCLUDES=/opt/homebrew/opt/icu4c/include
export PYICU_LFLAGS=-L/opt/homebrew/opt/icu4c/58.2/lib
You are now ready to follow the steps indicated by @Berkay 🤗
pip install pyicu
pip install morfessor
pip install pycld2
Upvotes: 1