Homebrewを使ってMacにmatplotlibとかipythonとかをインストールする
前回の続きで、Pythonで苦なく数値解析ができるような環境を整えていきます。
(前回→Homebrewを使ってMacにPython3とかNumpyとかScipyとかをインストールする - 開発のヒホ)
今回はMac(OSは10.9)にmatplotlib
、ipython
をインストールしていきます。
これで一通り環境が整うはずです。行列やベクトル計算、図の表示ぐらいならば余裕なはず。
0. 慣れている人向け
とりあえず以下のコマンド入力すれば環境は整うかもしれません。
matplotlib
brew install freetype sudo ln -s /usr/local/include/freetype2 /usr/include/freetype pip3 install matplotlib
ipython
pip3 install ipython
1. matplotlibのインストール
MATLABのような感じで図を描いてくれるライブラリです。
matplotlib - Wikipedia
まずは必要らしい物をインストール
brew install freetype
んでもってmatplotlibをインストール
pip3 install matplotlib
普通にインストールしようとするとerror: command 'clang' failed with exit status 1
なんてエラーが出ました。
エラーを追ってみると
# error # /usr/X11/include/ft2build.h:56:10: fatal error: 'freetype/config/ftheader.h' file not found # #include <freetype/config/ftheader.h>
だそうです。
なるほど、パスが通ってない。
sudo ln -s /usr/local/include/freetype2 /usr/include/freetype pip3 install matplotlib
これでインストール出来ました。
Successfully installed matplotlib python-dateutil tornado pyparsing nose six
などと表示されれば成功です。
2. ipythonをインストールする
普通にターミナルでpythonコードを書いてもいいのですが、補完してくれたりすると便利ですよね。
そのためにipythonを導入します。
Jupyter and the future of IPython — IPython
pip3 install ipython
Successfully installed ipython
と表示されていれば成功です。
3. 起動して図を描いてみる
sin波をプロットしてみます。
まずは先ほど導入したipythonを起動します。
ipython3 --pylab
この状態でpythonのコードを書くことが出来ます。
x = arange(0, 30, 0.1) y = sin(x) plot(x, y)
↓実行結果
いやはや、これは結構使えますね。