numpy, sciypy, matplotlib, pandas, scikit-learnの環境構築とかとか。

表題のライブラリ群の必要性が高まってきたので環境構築して遊ぶ。...のだけど環境構築に思った以上に手こずったので記す。

それにしてもPythonはこのあたりのライブラリが充実してるから逃げられないなぁ...。移行先希望。

環境

事前にvirtualenv, virtualenvwrapperでPythonの環境を切っておいた。

  • OSX 10.8.4
  • XCode4.8.2
  • Python 2.7.2
    • CPython2.7.2。今回はPyPyじゃないよ。PyPyじゃライブラリ動かないのあるから...。

インストール

% pip install numpy
% pip install scipy
% pip install matplotlib
% pip install pandas
% pip install scikit-learn


??tornadoがインストールされたのかはなぞである。

% pip freeze              
distribute==0.6.34
matplotlib==1.3.0
nose==1.3.0
numpy==1.7.1
pandas==0.12.0
pyparsing==2.0.1
python-dateutil==2.1
pytz==2013d
scikit-learn==0.14.1
scipy==0.12.0
six==1.4.1
tornado==3.1.1
wsgiref==0.1.2

ハマりどころ。

pip install scipyがコケる。

pip install sciypyすると、次のようなエラーが出た。

building 'dfftpack' library

error: library dfftpack has Fortran sources but no Fortran compiler found

----------------------------------------
Command /Users/rokujyouhitoma/.virtualenvs/analyze/bin/python -c "import setuptools;__file__='/Users/rokujyouhitoma/.virtualenvs/analyze/build/scipy/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/lc/vw5blb150gxd3_xwxj2k3s080000gn/T/pip-gv6NBX-record/install-record.txt --single-version-externally-managed --install-headers /Users/rokujyouhitoma/.virtualenvs/analyze/include/site/python2.7 failed with error code 1 in /Users/rokujyouhitoma/.virtualenvs/analyze/build/scipy
Storing complete log in /Users/rokujyouhitoma/.pip/pip.log

どうやらdfftpackというライブラリが足りないとわかるので、ググり記事に行き着く。

gfortran

どうやらgfortranが必要。

http://r.research.att.com/tools/からgcc-4.2 (Apple build 5666.3) with GNU Fortran 4.2.4 for Mac OS X 10.7 (Lion)をダウンロードし、インストール。

正しくインストールされたことを確認。

% gfortran-4.2 
i686-apple-darwin11-gfortran-4.2.1: no input files

#でもgfortranはみあたらず...。
% gfortranx   
zsh: command not found: gfortranx

#シンボリックリンクを貼って対応。
% sudo ln -s /usr/bin/gfortran-4.2 /usr/bin/gfortran

% gfortran --version
GNU Fortran (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING

#再度pip instal scipy
% pip install scipy

scipyってfortranに依存してるのね。

pip install matplotlibがコケる。

freetypeがないと怒られる。

============================================================================

                        * The following required packages can not be built:

                        * freetype

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /Users/rokujyouhitoma/.virtualenvs/analyze/build/matplotlib
Storing complete log in /Users/rokujyouhitoma/.pip/pip.log
freetypeのインストール
% curl -O http://ftp.twaren.net/Unix/NonGNU//freetype/freetype-2.5.0.1.tar.gz
% tar zxf freetype-2.5.0.1.tar.gz
% cd freetype-2.5.0.1
% ./configure
#エラー...libpngがないってさ( ꒪⌓꒪)...
checking for libpng... configure: error: `libpng-config' not found;
either set the LIBPNG_CFLAGS and LIBPNG_LDFLAGS environment variables,
or pass `--without-png' to the `configure' script.
make: *** [setup] Error 1
libpngのインストール
% http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.3/libpng-1.6.3.tar.gz
% tar zxf libpng-1.6.3.tar.gz
% cd libpng-1.6.3
% ./configure
% make
% sudo make install
% libpng-config --version
1.6.3
再度freetypeのインストール
% cd freetype-2.5.0.1
% ./configure
% make
% sudo make install
追記: brew installでfreetypeとlibpng

そもそもbrewで入れれるっぽい...

% brew install freetype
% brew install libpng

以上。

matplotlibは業務でちょびっと使った。numpyも業務とkivyの経路探索でお世話になったけど、まだまだ知識不足。なのでこれでやっと取り掛かれる。