polyglot
polyglot copied to clipboard
Can't from polyglot.text import Text on Mac OS X
I tried to use
from polyglot.text import Text in my source code and end with this
Traceback (most recent call last):
File "sj.py", line 6, in <module>
from polyglot.text import Text
File "//anaconda/lib/python3.5/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "//anaconda/lib/python3.5/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "//anaconda/lib/python3.5/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
File "//anaconda/lib/python3.5/site-packages/icu.py", line 37, in <module>
from docs import *
File "//anaconda/lib/python3.5/site-packages/docs.py", line 23, in <module>
from _icu import *
ImportError: dlopen(//anaconda/lib/python3.5/site-packages/_icu.cpython-35m-darwin.so, 2): Library not loaded: libicui18n.54.dylib
Referenced from: //anaconda/lib/python3.5/site-packages/_icu.cpython-35m-darwin.so
Reason: image not found
I installed before
brew install icu4c
then
pip install polyglot tried too CFLAGS=-I/usr/local/opt/icu4c/include LDFLAGS=-L/usr/local/opt/icu4c/lib pip install polyglot
I tried remove anaconda too but then I get:
Traceback (most recent call last):
File "sj.py", line 6, in <module>
from polyglot.text import Text
File "/usr/local/lib/python3.5/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "/usr/local/lib/python3.5/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/usr/local/lib/python3.5/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
but icu4c is installed
after installing pyicu
Traceback (most recent call last):
File "sj.py", line 6, in <module>
from polyglot.text import Text
File "/usr/local/lib/python3.5/site-packages/polyglot/text.py", line 9, in <module>
from polyglot.detect import Detector, Language
File "/usr/local/lib/python3.5/site-packages/polyglot/detect/__init__.py", line 1, in <module>
from .base import Detector, Language
File "/usr/local/lib/python3.5/site-packages/polyglot/detect/base.py", line 11, in <module>
from icu import Locale
File "/usr/local/lib/python3.5/site-packages/icu.py", line 37, in <module>
from docs import *
File "/usr/local/lib/python3.5/site-packages/docs.py", line 23, in <module>
from _icu import *
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/_icu.cpython-35m-darwin.so, 2): Library not loaded: libicui18n.54.dylib
Referenced from: /usr/local/lib/python3.5/site-packages/_icu.cpython-35m-darwin.so
Reason: image not found
Could you help me somehow? I need polyglot.text for my project but can't import it on mac
I'm experiencing this same issue:
Traceback (most recent call last):
File "/Users/brady/Desktop/LING 360/Final_Project/main.py", line 7, in
I'm on MacOSx Sierra, 10.12.1 with Anaconda experiencing the same issue.

@BradyHammond @robooo , I have a solution for all of us; On 11 Dec 2016, successfully installed polyglot on my Mac computer with Anaconda. My specs:
- macOS Sierra version 10.12.1
- Anaconda, conda version 4.2.13
- execute
conda --versionin terminal to see your version - Installed from here: https://repo.continuum.io/archive/Anaconda3-4.2.0-MacOSX-x86_64.sh
- execute
- Python version 3.5.2 (see this Gist to get Polyglot working in Python 2.7)
I made a Github Gist that automatically installs Polyglot on a Mac Computer running Anaconda. To run my gist just cut and paste this:
wget https://gist.githubusercontent.com/linwoodc3/8704bbf6d1c6130dda02bbc28967a9e6/raw/91d8e579c0fa66399ab1959c9aa94ea09c3eb539/polyglotOnMacOSX.sh -O polyglotOnMacOSX.sh && bash polyglotOnMacOSX.sh
I will also list the exact steps, but first, here are some important notes:
Key Facts/Problem Areas
- So far, this only works with Python 3.5
- My GitHub Gist has a fix for Python 2.7, but it's more involved. Will try to create
pyicumerge request
- My GitHub Gist has a fix for Python 2.7, but it's more involved. Will try to create
- Must use
easy_install pyicuand notpip install pyicu- installing pyicu with
pip install pyicualways leads toLibrary not loaded...error - I believe this has something to do with easy_install using a Python egg for install; have to research difference between pip and easy_install
- installing pyicu with
- Must use
conda install -c ccordoba12 icu=54.1- Found at https://anaconda.org/ccordoba12/icu
- ensure that you have
icu 54.1.1and noticu 58.1oricu 54.1.0. Just usingconda install icuwill not work!!
- The biggest problem is that
brew install icu4cuses version 58.1- Uses wrong version as you can see here: http://brewformulas.org/Icu4c. We need version 54.1 based on the output of each of our errors:
Library not loaded: libicui18n.54.dylib
Again, you can use my Github Gist to automatically test this on your machine. If you want to manually try the steps, they are
Exact Steps I used (tested several times)
- First, started from clean version of Anaconda, HomeBrew, etc. This is optional but it worked for me:
- brew uninstall --force icu4c
- brew update
- find $(brew --cache) -mindepth 1 -print -delete
Fresh install of anaconda :
* rm -rf anaconda # removes existing Anaconda install
Command Line Installer for Python 3 OS X downloaded on 11 Dec 2016 from: https://repo.continuum.io/archive/Anaconda3-4.2.0-MacOSX-x86_64.sh
Now the steps after Anaconda is installed:
- conda create -n icutest requests --no-deps -y
- source activate icutest
- conda install -c ccordoba12 icu=54.1
- https://anaconda.org/ccordoba12/icu
- conda install ipython jupyter notebook
- ipython
- !easy_install pyicu
- exit
- pip install polyglot
- ipython
- from polyglot.text import Text, Word
Or, you can use my gist to automatically test the install:
wget https://gist.githubusercontent.com/linwoodc3/8704bbf6d1c6130dda02bbc28967a9e6/raw/91d8e579c0fa66399ab1959c9aa94ea09c3eb539/polyglotOnMacOSX.sh -O polyglotOnMacOSX.sh && bash polyglotOnMacOSX.sh
looks good I could test on my mac (using yosemite) tomorrow. But what about 6th step? did you mean 'easy_install right'? without '!'?
Sorry for the confusion @robooo.
First, I think you could try this on your Yosemite comp; should work.
Step 6 is an artifact of running shell commands in ipython. If you follow my steps above, step 5 will put you in the interactive ipython interpreter. Then, to run commands, you need to add the ! in front. Here's why:
You can access shell commands in ipython by just appending an ! to the command, as stated in the documentation. I should have made that more clear. But, just for future's sake, if you have ipython running, you can run normal terminal commands in this way:
!ls # will run the normal ls command in the ipython interpreter.
Woooooohooooooo!!!!!!!!!!!!! Just got polyglot working in Python 2.7.12 locally. I'll made a gist for this as well, but it will require pyicu to accept a merge request (once I make one) and the original author of polyglot to maybe do something with an underlying dependency(https://github.com/aboSamoor/pycld2) for pip install to work.
Challenge is now figuring out how to get this up for everyone to use. I'm writing my notes here so I don't forget what I did:
- Cloned pyicu, created setup.cfg, created universal wheel, then reinstalled pycld2
- Create a conda Python 2.7 environment
- Had to clone the pyicu project, add a setup.cfg file to the repository,build a universal wheel, and clone and install pycld2(https://github.com/aboSamoor/pycld2).
git clone [email protected]:linwoodc3/pyicu.git- Change into the directory
cd pyicu - Use a text editor or vim to create the setup.cfg file: add EXACTLY this content to the
setup.cfgfile - run
python setup.py bdist_wheel --universalfrom thepyicurepository - Change to the distribution directory in
pyicurepositorycd dist/ - pip install the 2.7 wheel:
pip install PyICU-1.9.5-cp27-cp27m-macosx_10_6_x86_64.whl git clone http://github.com/abosamoor/pycld2.git- Change into the directory
cd pycld2/ - run
./setup.py install
Referenced from: /Applications/anaconda/lib/python3.6/site-packages/_icu.cpython-36m-darwin.so Reason: image not found
@linwoodc3 I used your gist but still get that error message, you said Python 3.5, so I have Python 3.6, don't think that would influence that. Can you help me please, really need polyglot for uni.
@AAyse I'll give it a try.
I got it to work @AAyse . Remember, this is for a Mac. The main change is you need to change the version from 3.5 to 3.6 in my script.
- Open Terminal
- Download the original
shfile.
wget https://gist.githubusercontent.com/linwoodc3/8704bbf6d1c6130dda02bbc28967a9e6/raw/786fc5074c811b3ec359135f2ce8d92d8413b33a/polyglotOnMacOSX35.sh
-
Now open and edit the
shfile on line 18 . You can open the file with Text Edit or anything.- The new line should read
conda create -n icutestenv python=3.6 --no-deps -y &&
- The new line should read
-
Now just run the script, and it should work (I got it working on my machine)
bash polyglotOnMacOSX35.sh
-
When the script finishes, make sure to select
noto keep the environment -
Now, just source into the new environment
source icutestenv
Here's proof this is working on Python 3.6.

@linwoodc3 Thank you very much. It works for me also now. Great help. Xx
I tried to get things running on a Mac with:
brew install icu4c
brew link icu4c --force
with no joy, but then trying:
pip3 install pyicu
pip3 install pycld2
pip3 install morfessor
seemed to work. (I'm not sure if the brew step was required?)
@linwoodc3 thanks for the answer, but by following step by step your protocol, I got this error:
from polyglot.text import Text, Word
Traceback (most recent call last):
File "
I'm working with 3.6.4 |Anaconda custom (64-bit). Any ideas on what's going on?
OK. Actually pip3 install PyICU solved all my issues
@audreyqvial did you try this https://github.com/aboSamoor/polyglot/issues/80#issuecomment-321953257
simplest way by far
If you are still struggling to install, this is a solution worth trying.
Anaconda makes this easy! Install Anaconda for your system, and then run this single line to have polyglot working on your system (python 3 or python 2 on Mac):
conda install -c conda-forge pyicu morfessor icu -y && pip install pycld2 polyglot
You must add the -c conda forge command as pyicu is only in that channel. If you do not want to install Anaconda, good luck. Life will be much harder or you will need to use that bash script I posted up above which may or may not work with tweaking.
>>> import icu
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/andi/Projects/vs/bookingstreet/vs-django-cms/bs/lib/python2.7/site-packages/icu/__init__.py", line 42, in <module>
from docs import *
File "/Users/andi/Projects/vs/bookingstreet/vs-django-cms/bs/lib/python2.7/site-packages/icu/docs.py", line 23, in <module>
from _icu import *
ImportError: dlopen(/Users/andi/Projects/vs/bookingstreet/vs-django-cms/bs/lib/python2.7/site-packages/_icu.so, 2): Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.59.dylib
Referenced from: /Users/andi/Projects/vs/bookingstreet/vs-django-cms/bs/lib/python2.7/site-packages/_icu.so
Reason: image not found
I ended up here because have my homebrew linked wrong version of pyciu4c
so I link specific installed version by brew switch command e.g I have icu4c both in version 59.1 and 62.1 and want use as major older one so I
brew switch icu4c 59.1
For me, the error "Library not loaded: libicui18n.54.dylib" was saying that it was expecting a previous version of icu4c, only for my it was version 60, and not 54. I finally found success getting polyglot to work by installing a previous version of icu4u -- nothing else seemed to work.
This tutorial was very useful for me:
http://hanxue-it.blogspot.com/2018/08/macos-homebrew-installing-older-version-of-software.html
The steps I followed are taken from this tutorial:
$ cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
I had to get a fuller history to find commits further back with this command:
git log -m -oneline -full-history --follow icu4c.rb
With the results, I found the exact commit that I needed for version 60.2 for the next command (in the blank space).
git checkout -b icu4c-60.2_______________
From there:
brew reinstall ./icu4c.rb
brew switch icu4c 60.2
This got it to work for me. I also found this stackoverflow discussion to be helpful: https://stackoverflow.com/questions/43780207/installing-node-with-brew-fails-on-mac-os-sierra/43784397