それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

ruby - mecab をインストールするときにエラーが出たのでメモ

mecab - ruby を使いたい

久しぶりにmecab をインストールしようとしたら・・・

bundle add mecab 

エラーになるんですね。

extconf.rb:12:in ``': No such file or directory - mecab-config

mecab は extconf で外部ライブラリ(.h)を参照するので、 mecabのインストールが必要でした。

エラーの原因:mecab が未インストールでした。

わたしは、macOS なので brew install します。

takuya@$ brew info mecab
mecab: stable 0.996 (bottled)
Yet another part-of-speech and morphological analyzer
https://taku910.github.io/mecab/
Conflicts with:
  mecab-ko (because both install mecab binaries)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mecab.rb

ああ、not installed だ。ずいぶん長い間使ってなかったんですね。つまりMacにしてから数年間一度もmacで使ってないわけだ。

mecab 本体のインストール

brew install mecab
brew install mecab-ipadic

これでインストールは完了

ruby mecab のインストール

bundle add mecab

無事終了しました。

Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 1.16.2
Fetching mecab 0.996
Installing mecab 0.996 with native extensions
Using romkan 0.4.0
Bundle complete! 2 Gemfile dependencies, 3 gems now installed.
Bundled gems are installed into `./vendor/bundle`

起動テストをします。

動かしてみます。

require 'mecab'
m = MeCab::Tagger.create("-Ochasen")
puts m.parse ("shachou")
bundle exec ruby sample.rb 
shachou shachou shachou 名詞-固有名詞-組織              
EOS

オッケ。

gem install でシステムに依存しない extconf にしてくれたら嬉しいんだけどなぁ。