Max OS X Yosemiteに octave をインストールする

Coursera の Machine Learningの講義で使うプログラム octave をインストールしようとして、つまづいた。

HomeBrewでインストール

下記のQiitaエントリーを参考に、HomeBrewでインストールしてみた。

記事にあるように、初期状態のHomeBrewのままだと、octaveはインストールできない。

$ brew install octave
Error: No available formula for octave 
Searching formulae...
Searching taps...
homebrew/science/octave     Caskroom/cask/octave    Caskroom/cask/octave

そこで、記事にあるように、homebrew/scienceをtapしてからインストールしてみる。

$ brew tap homebrew/science
$ brew install octave

これでインストールできた。

octaveの起動に失敗する

でも、octaveコマンドを実行すると、エラーが出てしまう。

$  octave
dyld: Library not loaded: /usr/local/lib/gcc/5/libgfortran.3.dylib
  Referenced from: /usr/local/Cellar/octave/3.8.2_1/bin/octave-cli-3.8.2
  Reason: image not found
[1]    18339 trace trap  octave

どうも、/usr/local/lib/gcc/5/というフォルダの下を探そうとしているんだけど、そんなフォルダは今の環境には無い。その代わり、/usr/local/lib/gcc/4.9/ならある。

$  ls /usr/local/lib/gcc
4.9

対策1

ググってみると、同じような問題はRのインストール時にも起きているようで、例えば下記記事などが参考になった。

ここでは、存在しないdylbを呼び出そうとしている元ファイルを、install_name_toolコマンドを使って書き換えている。

そこで、僕も真似してみたんだけど、今回は書き換えが1つのファイルだけでは済まずに、他のファイルでもいちいちnstall_name_toolフォルダの下を見に行こうとしていることが分かった。

これだと、何個のファイルを書き換えれば済むのか分からないよ…。orz

対策2

もう、安直な対策で片付けることにした。存在しない/usr/local/lib/gcc/5/のシンボリックリンクを作って、存在する/usr/local/lib/gcc/4.9/へと誘導する。

$ sudo ln -s /usr/local/lib/gcc/4.9 /usr/local/lib/gcc/5
Password:
$ ls /usr/local/lib/gcc
4.9 5

シンボリックリンクが張れたので、Octaveを実行してみる。

$ octave
GNU Octave, version 3.8.2
Copyright (C) 2014 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-apple-darwin14.3.0".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

octave:1>

うまくいった!

Comments