##エラー
Pythonでcabochaを使いたかったため、importしてみた
ipythonにて
In [1]: import CaboCha
ImportError: dlopen(/anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libiconv.2.dylib
Referenced from: /anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so
Reason: Incompatible library version: _CaboCha.cpython-36m-darwin.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0
共有ライブラリらへんでエラーがでているっぽい
ググってみたが
https://qiita.com/lapun/items/65039e59ac483c8dfd80
$ brew update
$ brew install libiconv
上のサイトのように試してみても変化なし
他にもportでupdateしようとしたが変化なし
##libiconv.2.dylibのversionの確認
$ otool -L /anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so
/anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so:
/usr/local/lib/libcabocha.5.dylib (compatibility version 6.0.0, current version 6.0.0)
/usr/local/lib/libcrfpp.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libmecab.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
@rpath/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
libiconv.2.dylibのversionはcurrent version 8.1.0
なのでいいはず、、、
libiconv.2.dylibは/usr/lib/libiconv.2.dylib
と/opt/local/lib/libiconv.2.dylib
があるらしい
今は@rpathに/usr/lib/
が入っており/usr/lib/libiconv.2.dylib
が使われているよう
##それぞれのversion確認
$ otool -L /usr/lib/libiconv.2.dylib
/usr/lib/libiconv.2.dylib:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
$ otool -L /opt/local/lib/libiconv.2.dylib
/opt/local/lib/libiconv.2.dylib:
/opt/local/lib/libiconv.2.dylib (compatibility version 9.0.0, current version 9.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
見てみると/opt/local/lib/libiconv.2.dylib
を使えば良さそう
##libiconv.2.dylibを置き換える
$ sudo install_name_tool -change "@rpath/libiconv.2.dylib" "/opt/local/lib/libiconv.2.dylib" /anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so
参考:https://qiita.com/itoru257/items/d36b4e3908a39bfbbb18
すると
$ otool -L /anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so
/anaconda/lib/python3.6/site-packages/_CaboCha.cpython-36m-darwin.so:
/usr/local/lib/libcabocha.5.dylib (compatibility version 6.0.0, current version 6.0.0)
/usr/local/lib/libcrfpp.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libmecab.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 104.1.0)
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
pathが置き換わっている(current versionは変わってない、、)のでimportしてみる
In [1]: import CaboCha
In [2]:
###importできた!
(/opt/local/lib/libiconv はmacportsでupgradeできるっぽいのだが、/usr/lib/libiconv.2.dylib のupgradeの方法がわからなかったので、前者に置き換えた感じ)