日本語が苦手で用語が曖昧かもしれません。お許しください。
MeCabとCaboChaをMacに導入してPythonから使ってみる
上記ページに参考してcabocha-pythonをMacで使いたいんです。コマンドラインでCabochaが使えますが、以下のコマンドでインストールしたPythonバインディングでPythonから使えないです。
以下のコマンドでcabocha-pythonをインストールできました。
% curl -OL https://github.com/taku910/cabocha/archive/master.zip
% unzip master.zip
% cd cabocha-master
% pip install python/
Processing ./python
Preparing metadata (setup.py) ... done
Building wheels for collected packages: cabocha-python
Building wheel for cabocha-python (setup.py) ... done
Created wheel for cabocha-python: filename=cabocha_python-0.69-cp310-cp310-macosx_11_0_arm64.whl size=24383 sha256=a9c5035bf5d53158daf77308a32ed7fe15f4fab17f551cbc3807ba0a19bb62d1
Stored in directory: /private/var/folders/26/9wdtrsyd4mxcx7wh7m398khc0000gn/T/pip-ephem-wheel-cache-268kjen1/wheels/e6/a3/17/93356be0304ed4b17e7d14180b217eacbd9c7075cb4065f167
Successfully built cabocha-python
Installing collected packages: cabocha-python
Successfully installed cabocha-python-0.69
でも、実際に使ってみると、エラーが出てきました。
/Users/hurui05/anaconda3/bin/python3.10 /Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py
Traceback (most recent call last):
File "/Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py", line 781, in <module>
run_cabocha_demo()
File "/Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py", line 749, in run_cabocha_demo
import CaboCha
File "/Users/hurui05/anaconda3/lib/python3.10/site-packages/CaboCha.py", line 28, in <module>
_CaboCha = swig_import_helper()
File "/Users/hurui05/anaconda3/lib/python3.10/site-packages/CaboCha.py", line 24, in swig_import_helper
_mod = imp.load_module('_CaboCha', fp, pathname, description)
File "/Users/hurui05/anaconda3/lib/python3.10/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/hurui05/anaconda3/lib/python3.10/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '__ZN7CaboCha12createParserEPKc'
以下のページで似たような問題が記述されていましたが、解決方法は私の場合には役に立たないみたいです。
macでmecab-python3のimport error(Symbol not found)を解決
% otool -L /Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so
/Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so:
/usr/local/lib/libcrfpp.0.dylib (compatibility version 1.0.0, current version 1.0.0)
@rpath/libiconv.2.dylib (compatibility version 9.0.0, current version 9.1.0)
@rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
% ls /opt/homebrew/lib
libcrfpp.0.dylib libcrfpp.dylib libgmp.a libgmpxx.4.dylib libgmpxx.dylib
libcrfpp.a libgmp.10.dylib libgmp.dylib libgmpxx.a pkgconfig
install_tool_name -change
を使ってみると、
% install_name_tool -change "/usr/local/lib/libcrfpp.0.dylib" /opt/homebrew/lib/libcrfpp.0.dylib /Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so
% otool -L /Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so
/Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so:
/opt/homebrew/lib/libcrfpp.0.dylib (compatibility version 1.0.0, current version 1.0.0)
@rpath/libiconv.2.dylib (compatibility version 9.0.0, current version 9.1.0)
@rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)
結局同じエラーが出てきました。
/Users/hurui05/anaconda3/bin/python3.10 /Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py
Traceback (most recent call last):
File "/Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py", line 781, in <module>
run_cabocha_demo()
File "/Users/hurui05/Desktop/mecab/frontend/src/cleaners/pseudo_cleaner.py", line 749, in run_cabocha_demo
import CaboCha
File "/Users/hurui05/anaconda3/lib/python3.10/site-packages/CaboCha.py", line 28, in <module>
_CaboCha = swig_import_helper()
File "/Users/hurui05/anaconda3/lib/python3.10/site-packages/CaboCha.py", line 24, in swig_import_helper
_mod = imp.load_module('_CaboCha', fp, pathname, description)
File "/Users/hurui05/anaconda3/lib/python3.10/imp.py", line 243, in load_module
return load_dynamic(name, filename, file)
File "/Users/hurui05/anaconda3/lib/python3.10/imp.py", line 343, in load_dynamic
return _load(spec)
ImportError: dlopen(/Users/hurui05/anaconda3/lib/python3.10/site-packages/_CaboCha.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '__ZN7CaboCha12createParserEPKc'
助けてください!