aboSamoor / polyglot

Multilingual text (NLP) processing toolkit
http://polyglot-nlp.com
Other
2.31k stars 337 forks source link

Can't from polyglot.text import Text on Mac OS X #80

Open robooo opened 7 years ago

robooo commented 7 years ago

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

BradyHammond commented 7 years ago

I'm experiencing this same issue:

Traceback (most recent call last): File "/Users/brady/Desktop/LING 360/Final_Project/main.py", line 7, in from polyglot.text import Text File "/Users/brady/Library/Python/3.5/lib/python/site-packages/polyglot/text.py", line 9, in from polyglot.detect import Detector, Language File "/Users/brady/Library/Python/3.5/lib/python/site-packages/polyglot/detect/init.py", line 1, in from .base import Detector, Language File "/Users/brady/Library/Python/3.5/lib/python/site-packages/polyglot/detect/base.py", line 11, in from icu import Locale File "/usr/local/lib/python3.5/site-packages/icu.py", line 37, in from docs import File "/usr/local/lib/python3.5/site-packages/docs.py", line 23, in 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

linwoodc3 commented 7 years ago

I'm on MacOSx Sierra, 10.12.1 with Anaconda experiencing the same issue.

screen shot 2016-12-07 at 4 51 58 am

linwoodc3 commented 7 years ago

@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:

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

  1. So far, this only works with Python 3.5
  2. Must use easy_install pyicu and not pip install pyicu
    • installing pyicu with pip install pyicu always leads to Library 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
  3. Must use conda install -c ccordoba12 icu=54.1
  4. The biggest problem is that brew install icu4c uses version 58.1
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)

  1. 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:

  1. conda create -n icutest requests --no-deps -y
  2. source activate icutest
  3. conda install -c ccordoba12 icu=54.1
    1. https://anaconda.org/ccordoba12/icu
  4. conda install ipython jupyter notebook
  5. ipython
  6. !easy_install pyicu
  7. exit
  8. pip install polyglot
  9. ipython
  10. 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
robooo commented 7 years ago

looks good I could test on my mac (using yosemite) tomorrow. But what about 6th step? did you mean 'easy_install right'? without '!'?

linwoodc3 commented 7 years ago

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.
linwoodc3 commented 7 years ago

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:

  1. Cloned pyicu, created setup.cfg, created universal wheel, then reinstalled pycld2

Use my Gist to get Polyglot working on Python 2.7.

AAyse commented 7 years ago

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.

linwoodc3 commented 7 years ago

@AAyse I'll give it a try.

linwoodc3 commented 7 years ago

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.

  1. Open Terminal
  2. Download the original sh file.

wget https://gist.githubusercontent.com/linwoodc3/8704bbf6d1c6130dda02bbc28967a9e6/raw/786fc5074c811b3ec359135f2ce8d92d8413b33a/polyglotOnMacOSX35.sh
  1. Now open and edit the sh file 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 &&
  2. Now just run the script, and it should work (I got it working on my machine)

    • bash polyglotOnMacOSX35.sh
  3. When the script finishes, make sure to select no to keep the environment

  4. Now, just source into the new environment source icutestenv

linwoodc3 commented 7 years ago

Here's proof this is working on Python 3.6.

image

AAyse commented 7 years ago

@linwoodc3 Thank you very much. It works for me also now. Great help. Xx

psychemedia commented 7 years ago

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?)

audreyqvial commented 6 years ago

@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 "", line 1, in File "/anaconda3/lib/python3.6/site-packages/polyglot/text.py", line 9, in from polyglot.detect import Detector, Language File "/anaconda3/lib/python3.6/site-packages/polyglot/detect/init.py", line 1, in from .base import Detector, Language File "/anaconda3/lib/python3.6/site-packages/polyglot/detect/base.py", line 11, in from icu import Locale File "/anaconda3/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-macosx-10.7-x86_64.egg/icu/init.py", line 37, in from _icu import * ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-macosx-10.7-x86_64.egg/_icu.cpython-36m-darwin.so, 2): Symbol not found: __ZNK6icu_5414LEFontInstance10canDisplayEi Referenced from: /anaconda3/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-macosx-10.7-x86_64.egg/_icu.cpython-36m-darwin.so Expected in: flat namespace in /anaconda3/lib/python3.6/site-packages/PyICU-2.0.3-py3.6-macosx-10.7-x86_64.egg/_icu.cpython-36m-darwin.so

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

linwoodc3 commented 6 years ago

@audreyqvial did you try this https://github.com/aboSamoor/polyglot/issues/80#issuecomment-321953257

linwoodc3 commented 6 years ago

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.

andilabs commented 6 years ago
>>> 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
sarahrahrah commented 5 years ago

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