I have tried to make use of some code, I had set up before in a python file. However, I run in an error. If I use mecab in terminal it works as expected:
% mecab
君の名は
君 名詞,代名詞,一般,*,*,*,君,キミ,キミ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
名 名詞,一般,*,*,*,*,名,ナ,ナ
は 助詞,係助詞,*,*,*,*,は,ハ,ワ
EOS
If I run MeCab in this script, it's getting an import error:
import MeCab
sent ="君の名は"
tagger = MeCab.Tagger()
print(tagger.parse(sent))
(I have also tried versions, where I defined the path for the dictionaries (and tried several ones, unidic, ipadic, neologd) '-d /opt/homebrew/lib/mecab/dic/ipadic'
The error I get is quite common and I found a lot of attempts to fix it online, none of which have been working for me:
ImportError
dlopen(/Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '__ZN5MeCab11createModelEPKc'
File "/Users/username/Desktop/importMeCab.py", line 1, in <module>
import MeCab
ImportError: dlopen(/Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '__ZN5MeCab11createModelEPKc'
One suggestion was to build everything from source again. (I did, it still didn't work for the python script)
Other suggestions were to upgrade pip and check with otool for the expected files
/usr/lib/libmecab.dylib
/usr/lib/libc++.1.dylib
/usr/lib/libSystem.B.dylib
otool -L /Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so
/Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so (architecture x86_64):
@loader_path/../mecab-python3.dylibs/libmecab.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.23.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
/Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so (architecture arm64):
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.23.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
and reassign the path from /usr/lib/ to the actual one (just as the author I only found libmecab.dylib
in the /opt/homebrew/lib
folder) with % install_name_tool -change "expected path" [actual-path] /Users/username/.pyenv/versions/3.11.1/lib/python3.11/site-packages/MeCab/_MeCab.cpython-311-darwin.so
and so it worked for the author, but I still receive the error.
I have also seen this guide, but am unsure how to make the libraries "match" as suggested in the best rated answer.
Specs:
Mac Ventura 13.3.1 M1 Chip
MeCab 0.996
MeCab-Python3 1.0.6
Python 3.11.1 (through pyenv)
Unidic 1.1.0