Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wheel for macOS requires Mecab to run #18

Closed
HiromuHota opened this issue Jun 3, 2020 · 7 comments · Fixed by #19
Closed

Wheel for macOS requires Mecab to run #18

HiromuHota opened this issue Jun 3, 2020 · 7 comments · Fixed by #19
Labels
help wanted Extra attention is needed osx Mac OSX related issues

Comments

@HiromuHota
Copy link

https://github.com/polm/fugashi/releases/tag/v0.2.0 said

it's possible to install fugashi without MeCab

I confirmed that it is possible to install fugashi and run without Mecab on Linux (Ubuntu 18.04).
However, I was not able to run fugashi without Mecab on macOS, though it is possible to install fugashi without it.
Is this by design or an unexpected behaviour?

Without Mecab

(venv) fugashi $ mecab --version
-bash: mecab: command not found
(venv) fugashi $ pip list | grep fugashi
fugashi    0.2.2
(venv) fugashi $ python
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fugashi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/hiromu/workspace/fugashi/venv/lib/python3.7/site-packages/fugashi.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/lib/libmecab.2.dylib
  Referenced from: /Users/hiromu/workspace/fugashi/venv/lib/python3.7/site-packages/fugashi.cpython-37m-darwin.so
  Reason: image not found

With Mecab

(venv) fugashi $ brew install mecab
==> Downloading https://homebrew.bintray.com/bottles/mecab-0.996.catalina.bottle.3.tar.gz
Already downloaded: /Users/hiromu/Library/Caches/Homebrew/downloads/152cd5889822b8a9cf8247aab5a4b333f1206e1bf56aa3217c9e5b6928318258--mecab-0.996.catalina.bottle.3.tar.gz
==> Pouring mecab-0.996.catalina.bottle.3.tar.gz
🍺  /usr/local/Cellar/mecab/0.996: 20 files, 4.2MB
(venv) fugashi $ mecab --version
mecab of 0.996

(venv) fugashi $ pip list | grep fugashi
fugashi    0.2.2
(venv) fugashi $ python
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fugashi
>>> fugashi.__file__
'/Users/hiromu/workspace/fugashi/venv/lib/python3.7/site-packages/fugashi.cpython-37m-darwin.so'

OS: macOS (10.15.4)
Python: 3.7.7
fugashi: 0.2.2

@polm
Copy link
Owner

polm commented Jun 3, 2020

That's not intentional, that's a bug. Thanks for the report.

I'll take a look at this and try to figure out what's up, but I'll need help testing it.

@polm polm added help wanted Extra attention is needed osx Mac OSX related issues labels Jun 3, 2020
@polm
Copy link
Owner

polm commented Jun 3, 2020

Suspect I just need to use delocate as an alternative to the manylinux-only auditwheel repair. Will give it a shot tomorrow.

@HiromuHota
Copy link
Author

I installed delocate and tested the wheel that you built.

Without Mecab

(venv) fugashi $ wget https://files.pythonhosted.org/packages/f1/b4/f10acc870688e1de6fef88e771344dd1e289b8e525acd240ce36ee93b663/fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl
(venv) fugashi $ delocate-listdeps fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl 
/usr/local/lib/libmecab.2.dylib
(venv) fugashi $ ls /usr/local/lib/libmecab.2.dylib
ls: /usr/local/lib/libmecab.2.dylib: No such file or directory

With Mecab

(venv) fugashi $ mecab --version
mecab of 0.996

(venv) fugashi $ delocate-listdeps fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl 
/usr/local/Cellar/mecab/0.996/lib/libmecab.2.dylib
(venv) fugashi $ ls /usr/local/Cellar/mecab/0.996/lib/libmecab.2.dylib
/usr/local/Cellar/mecab/0.996/lib/libmecab.2.dylib

@HiromuHota
Copy link
Author

I tried delocate-wheel to copy the dylib into the wheel file as below, but nothing actually happened, probably due to a reported issue (matthew-brett/delocate#39 is an opened PR to fix this).

(venv) fugashi $ delocate-wheel -w fixed_wheels -v fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl 
Fixing: fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl

I tried a workaround (matthew-brett/delocate#72 (comment)) and it worked.
The workaround is sort of manually copying the required dylib into the wheel.

The fixed wheel looks like this:

(venv) HHMBP fugashi $ unzip -t fixed_wheels/fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl 
Archive:  fixed_wheels/fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl
    testing: fugashi-0.2.2.data/scripts/fugashi   OK
    testing: fugashi-0.2.2.data/scripts/fugashi-info   OK
    testing: fugashi-0.2.2.dist-info/RECORD   OK
    testing: fugashi-0.2.2.dist-info/LICENSE   OK
    testing: fugashi-0.2.2.dist-info/WHEEL   OK
    testing: fugashi-0.2.2.dist-info/top_level.txt   OK
    testing: fugashi-0.2.2.dist-info/METADATA   OK
    testing: fugashi.cpython-37m-darwin.so   OK
    testing: fugashi.dylibs/libmecab.2.dylib   OK

This is the original wheel:

(venv) HHMBP fugashi $ unzip -t fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl 
Archive:  fugashi-0.2.2-cp37-cp37m-macosx_10_14_x86_64.whl
    testing: fugashi.cpython-37m-darwin.so   OK
    testing: fugashi-0.2.2.data/scripts/fugashi   OK
    testing: fugashi-0.2.2.data/scripts/fugashi-info   OK
    testing: fugashi-0.2.2.dist-info/LICENSE   OK
    testing: fugashi-0.2.2.dist-info/METADATA   OK
    testing: fugashi-0.2.2.dist-info/WHEEL   OK
    testing: fugashi-0.2.2.dist-info/top_level.txt   OK
    testing: fugashi-0.2.2.dist-info/RECORD   OK

@polm
Copy link
Owner

polm commented Jun 4, 2020

Thanks again for the PR. I made a new release (0.2.3) that includes the dylib, can you confirm it works as intended?

@HiromuHota
Copy link
Author

Thanks for merging #19.
I tested and confirmed that it worked as expected.

(venv) fugashi $ pip list | grep fugashi
fugashi              0.2.3
(venv) fugashi $ pip list | grep unidic-lite
unidic-lite          1.0.6
(venv) fugashi $ mecab --version
-bash: mecab: command not found
(venv) fugashi $ python
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fugashi
>>> 
>>> 
>>> from fugashi import Tagger
>>> 
>>> tagger = Tagger('-Owakati')
>>> text = "麩菓子は、麩を主材料とした日本の菓子。"
>>> tagger.parse(text)
'麩 菓子 は 、 麩 を 主材 料 と し た 日本 の 菓子 。'
>>> # => '麩 菓子 は 、 麩 を 主材 料 と し た 日本 の 菓子 。'
>>> for word in tagger(text):
...     print(word, word.feature.lemma, word.pos, sep='\t')
...     # "feature" is the Unidic feature data as a named tuple
... 
麩	麩	名詞,普通名詞,一般,*
菓子	菓子	名詞,普通名詞,一般,*
は	は	助詞,係助詞,*,*
、	、	補助記号,読点,*,*
麩	麩	名詞,普通名詞,一般,*
を	を	助詞,格助詞,*,*
主材	主材	名詞,普通名詞,一般,*
料	料	接尾辞,名詞的,一般,*
と	と	助詞,格助詞,*,*
し	為る	動詞,非自立可能,*,*
た	た	助動詞,*,*,*
日本	日本	名詞,固有名詞,地名,国
の	の	助詞,格助詞,*,*
菓子	菓子	名詞,普通名詞,一般,*
。	。	補助記号,句点,*,*

Just FYI, spaCy also worked as expected.

(venv) fugashi $ pip list | grep spacy
spacy                2.2.4
(venv) fugashi $ python
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
ja = spacy.blank('ja')
for word in ja('日本語ですよ'):
    print(word, word.lemma_, word.tag_, word.pos_)
>>> ja = spacy.blank('ja')
>>> for word in ja('日本語ですよ'):
...     print(word, word.lemma_, word.tag_, word.pos_)
... 
日本 日本 名詞,固有名詞,地名,国 PROPN
語 語 名詞,普通名詞,一般,* NOUN
です です 助動詞,*,*,* AUX
よ よ 助詞,終助詞,*,* PART

@polm
Copy link
Owner

polm commented Jun 4, 2020

Thanks for confirming and for writing the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed osx Mac OSX related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants