Closed takayuki1997 closed 3 years ago
Thanks for your interest.
Actually, this library assumes that you have mecab installed. https://taku910.github.io/mecab/ It's a hassle, but please do the following steps to install mecab from source files, and then install RMeCab. First, install the development environment on Mac. Launch a terminal and type the commad.
$ xcode-select --install
Then, download two source files of MeCab , and build and install them.
$ cd ~/Downloads
$ curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE' -o mecab-0.996.tar.gz
$ tar xf mecab-0.996.tar.gz
$ cd mecab-0.996
$ ./configure --with-charset=utf8
$ make
$ sudo make install
$ cd ~/Downloads
$ curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7MWVlSDBCSXZMTXM' -o mecab-ipadic-2.7.0-20070801.tar.gz
$ tar zvxf mecab-ipadic-2.7.0-20070801.tar.gz
$ tar xf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf-8
$ make
$ sudo make install
Check if it is working.
$ mecab
すもももももももものうち
type ctrl + C to stop mecab.
Finally, you can install RMeCab on R or RStudio
install.packages("RMeCab", repos = "https://rmecab.jp/R", type = "source")
Thank you for the reply. But I have already installed mecab. Though, I failed installation of RMeCab. I would appreciate your comments.
takayuki@pc51-185 ~ % mecab
すもももももももものうち
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
^C
takayuki@pc51-185 ~ %
Please quote the error message on R
on R
> install.packages("RMeCab", repos = "https://rmecab.jp/R", type = "source")
trying URL 'https://rmecab.jp/R/src/contrib/RMeCab_1.07.tar.gz'
Content type 'application/x-gzip' length 1473940 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c Ngram.cpp -o Ngram.o
The downloaded source packages are in
‘/private/var/folders/b1/yxyz_lls18j6s77bh2np7rkr0000gp/T/RtmpZeCnE7/downloaded_packages’
Warning message:
In install.packages("RMeCab", repos = "https://rmecab.jp/R", type = "source") :
installation of package ‘RMeCab’ had non-zero exit status
> library(RMeCab)
Error: package or namespace load failed for ‘RMeCab’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so, 6): Library not loaded: /usr/local/lib/libmecab.2.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so
Reason: image not found
on RStudio
> install.packages("RMeCab", repos = "https://rmecab.jp/R", type = "source")
trying URL 'https://rmecab.jp/R/src/contrib/RMeCab_1.07.tar.gz'
Content type 'application/x-gzip' length 1473940 bytes (1.4 MB)
==================================================
downloaded 1.4 MB
* installing *source* package ‘RMeCab’ ...
** using staged installation
** libs
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c Ngram.cpp -o Ngram.o
In file included from Ngram.cpp:2:
./RMeCab.h:25:10: error: 'mecab.h' file not found with <angled> include; use "quotes" instead
#include <mecab.h>
^~~~~~~~~
"mecab.h"
1 error generated.
make: *** [Ngram.o] Error 1
ERROR: compilation failed for package ‘RMeCab’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab’
Warning in install.packages :
installation of package ‘RMeCab’ had non-zero exit status
The downloaded source packages are in
‘/private/var/folders/b1/yxyz_lls18j6s77bh2np7rkr0000gp/T/Rtmpk7k6uv/downloaded_packages’
> library(RMeCab)
Error: package or namespace load failed for ‘RMeCab’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so, 6): Library not loaded: /usr/local/lib/libmecab.2.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so
Reason: image not found
Sorry, I did not read your first message carefully. Did you install mecab with brew?
What happens if you simply try the following?
install.packages("RMeCab", repos = "http://rmecab.jp/R")
Yes. I installed mecab with brew.
I got following messages.
> install.packages("RMeCab", repos = "https://rmecab.jp/R")
trying URL 'https://rmecab.jp/R/bin/macosx/big-sur-arm64/contrib/4.1/RMeCab_1.07.tgz'
Content type 'application/x-gzip' length 170573 bytes (166 KB)
==================================================
downloaded 166 KB
The downloaded binary packages are in
/var/folders/b1/yxyz_lls18j6s77bh2np7rkr0000gp/T//RtmpZeCnE7/downloaded_packages
> library(RMeCab)
Error: package or namespace load failed for ‘RMeCab’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so, 6): Library not loaded: /usr/local/lib/libmecab.2.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RMeCab/libs/RMeCab.so
Reason: image not found
As the error message says、there seems to be no link to libmecab.2.dylib,
/usr/local/lib/libmecab.dylib -> /usr/local/lib/libmecab.2.dylib
for example, in the terminal type
"brew link mecab"
and install again RMeCab. Does this work?
I got following messages in Terminal.
takayuki@pc51-188 ~ % brew link mecab
Warning: Already linked: /opt/homebrew/Cellar/mecab/0.996
To relink:
brew unlink mecab && brew link mecab
takayuki@pc51-188 ~ % brew unlink mecab && brew link mecab
Unlinking /opt/homebrew/Cellar/mecab/0.996... 7 symlinks removed.
Linking /opt/homebrew/Cellar/mecab/0.996... 7 symlinks created.
After that, I still have same symptoms.
There are two possibilities I can think of right now. One is that the link to the lib/libmecab is broken. The other is that the mecab installed by homebrew is not built for M1 architecture. please check with lipo -info /usr/local/lib/libmecab
takayuki@pc51-188 ~ % lipo -info /usr/local/lib/libmecab
fatal error: /Library/Developer/CommandLineTools/usr/bin/lipo: can't open input file: /usr/local/lib/libmecab (No such file or directory)
I installed homebrew again.
takayuki@pc51-188 ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then
takayuki@pc51-188 ~ % brew reinstall mecab
==> Downloading https://ghcr.io/v2/homebrew/core/mecab/manifests/0.996-3
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mecab/blobs/sha256:495c42533a5ea5bdedcf4a95c05e613c3579f626b17d0df0396d8
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:495c42533a5ea5bdedcf4a95c05e613c3579
######################################################################## 100.0%
==> Reinstalling mecab
==> Pouring mecab--0.996.arm64_big_sur.bottle.3.tar.gz
🍺 /opt/homebrew/Cellar/mecab/0.996: 20 files, 4.5MB
takayuki@pc51-188 ~ % brew reinstall mecab-ipadic
==> Downloading https://ghcr.io/v2/homebrew/core/mecab-ipadic/manifests/2.7.0-20070801
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mecab-ipadic/blobs/sha256:bdd2a69bbcbfe6e051278c94e4e19c6bfde63e2a3e525e
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:bdd2a69bbcbfe6e051278c94e4e19c6bfde6
######################################################################## 100.0%
==> Reinstalling mecab-ipadic
==> Pouring mecab-ipadic--2.7.0-20070801.arm64_big_sur.bottle.tar.gz
==> Caveats
To enable mecab-ipadic dictionary, add to /opt/homebrew/etc/mecabrc:
dicdir = /opt/homebrew/lib/mecab/dic/ipadic
==> Summary
🍺 /opt/homebrew/Cellar/mecab-ipadic/2.7.0-20070801: 16 files, 50.6MB
But
takayuki@pc51-188 ~ % lipo -info /usr/local/lib/libmecab
fatal error: /Library/Developer/CommandLineTools/usr/bin/lipo: can't open input file: /usr/local/lib/libmecab (No such file or directory)
From the install message above, I got that your mecab may be M1 compatible, and for Apple Silicon machines, binaries and shared libraries are located /opt/homebrew/*. So i'm not sure but maybe you can type:
lipo -info /opt/homebrew/lib/libmecab.2.dylib
Now, I think you have to create symbolic link to homebrew path in MacOS system path or reset DYLD_LIBRARY_PATH in your enviroment file. However, I am not using homebrew on my M1 Mac, so I need to look into the details.
But if you don not have any special reason to install mecab with homebrew, I think it will save you time to uninstall mecab and mecab dictionry installed with homebrew, and install them from the source files using the method described above in this thread. MeCab is rarely updated, so I don't think it needs to be managed by homebrew.
takayuki@pc51-188 ~ % lipo -info /opt/homebrew/lib/libmecab.2.dylib
Non-fat file: /opt/homebrew/lib/libmecab.2.dylib is architecture: arm64
takayuki@pc51-188 ~ % ls -l /opt/homebrew/lib/
total 0
lrwxr-xr-x 1 takayuki admin 42 7 16 08:50 libmecab.2.dylib -> ../Cellar/mecab/0.996/lib/libmecab.2.dylib
lrwxr-xr-x 1 takayuki admin 36 7 16 08:50 libmecab.a -> ../Cellar/mecab/0.996/lib/libmecab.a
lrwxr-xr-x 1 takayuki admin 40 7 16 08:50 libmecab.dylib -> ../Cellar/mecab/0.996/lib/libmecab.dylib
drwxr-xr-x 3 takayuki admin 96 7 16 08:51 mecab
I will uninstall mecab and mecab-ipadic once, then try to install them from the source files. I will report the result later.
For reference. I'm not sure, but the following process may enable you to use the Homebrew version.
sudo ln -s /opt/homebrew/Cellar/mecab/0.996/lib/libmecab.2.dylib /usr/local/lib/libmecab.dylib
sudo mkdir /usr/local/lib/mecab
sudo mkdir /usr/local/lib/mecab/dic
sudo ln -s /opt/homebrew/Cellar/mecab-ipadic/2.7.0-20070801/lib/mecab/dic/ipadic /usr/local/lib/mecab/dic/ipadic
If it doesn't work, remove the links as follows:
sudo unlink /usr/local/lib/libmecab.dylib
sudo unlink /usr/local/lib/mecab/dic/ipadic
sudo rmdir /usr/local/lib/mecab/dic
sudo rmdir /usr/local/lib/mecab
Working! Thank you very much for your kindness and logical instructions.
MacBook Air M1, 2020, OS11.4 mecab: 0.996 mecab-ipadic: 2.7.0-20070801 RMeCab: 1.07 R: 4.1.0 RStudio: 1.4.1717
$ xcode-select --install
$ cd ~/Downloads
$ curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE' -o mecab-0.996.tar.gz
$ tar xf mecab-0.996.tar.gz
$ cd mecab-0.996
$ ./configure --with-charset=utf8
$ make
$ sudo make install
$ cd ~/Downloads
$ curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7MWVlSDBCSXZMTXM' -o mecab-ipadic-2.7.0-20070801.tar.gz
$ tar zvxf mecab-ipadic-2.7.0-20070801.tar.gz
$ tar xf mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf8
$ make
$ sudo make install
$ mecab
すもももももももものうち
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
^C
> install.packages("RMeCab", repos = "https://rmecab.jp/R", type = "source")
> library(RMeCab)
> res <- RMeCabC("すもももももももものうち")
> unlist(res)
名詞 助詞 名詞 助詞 名詞 助詞 名詞
"すもも" "も" "もも" "も" "もも" "の" "うち"
I found small typo. $ xcode-select -install $ xcode-select --install
$ ./configure –with-charset=utf8 $ ./configure --with-charset=utf8
Thank you for pointing out the typos. If you have any further questions, please feel free to contact me at any time.
Thank you so much, this worked for me!
Dear Dr. Ishda,
I am trying to install RMeCab 1.07 on M1 Mac (MacBook Air M1, 2020, OS11.4). I can run mecab in Terminal. But I can not use RMeCab.
Version of R: 4.1.0 Version of RStudio: 1.4.1717
Other method
This method does not work either.
I failed the installation by these methods. What should I do for installation?