"Diary" インターネットさんへの恩返し

いつもソースコードコピペばかりなので,みなさまへ少しばかりの恩返しを

python のPILで画像処理を試してみる(分析系モジュールインストール編)



スポンサーリンク

pythonで画像ファイルの色分布を出してみる。
その前に必要な分析系モジュールをインストールする。

1.分析計算用のモジュールとかをインストール

numpyのインストール

numpyは、多次元配列(例えばベクトルや行列などを表現できる)のサポートや数学関数ライブラリです。

pip install numpy 
pandas pandas(Python Data Analysis Library)のインストール
pip install pandas

ubuntuの場合で以下のエラーが出る時は「sudo apt-get install g++ 」を実行後、「pip install pandas」を再実行。

cc: error trying to exec 'cc1plus': execvp: No such file or directory pandas
sipyのインストール

エラー出た。Blasライブラリがないとのこと。

pip install scipy

・
・
・
numpy.distutils.system_info.BlasNotFoundError:
    Blas (http://www.netlib.org/blas/) libraries not found.
    Directories to search for the libraries can be specified in the
    numpy/distutils/site.cfg file (section [blas]) or by setting
    the BLAS environment variable.


ググるとscipyのインストールガイドに、Windows用のインストーラーでインストールするように書いてあったので、ここから Download scipy-0.13.2-win32-superpack-python2.7.exeをダウンロードしインストールする。

残念が32bitアプリのため64bitのpythonとうまいこと噛み合わず以下のエラー

>>> import scipy.stats
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 324, in <module>
    from .stats import *
  File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 242, in <module>
    import scipy.special as special
  File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 531, in <module>
    from ._ufuncs import *
ImportError: DLL load failed: %1 は有効な Win32 アプリケーションではありません。
>>>

やりおなし、例の64bitバイナリがそろうこのサイトからscipy-0.13.2.win-amd64-py2.7.exeをダウンロードしてインストールする。

以下見ると64bit系で全部揃えるの難しいので32bitで揃えたほうがいいとあった。くそーいまさらか。

・分生ツールセットアップ
データ分析がデキるITエンジニアになるために必要な「道具」を揃える」にデータサイエンティストちっくなモジュールがいろいろ書かれていました。

ubuntuの場合で以下のエラーがでるときは、「sudo apt-get install liblapack-dev」を実行した後に、「sudo pip install scipy」を実行。

numpy.distutils.system_info.NotFoundError: no lapack/blas resources found

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/vagrant/build/scipy/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-Yyd7Pp-record/install-record.txt failed with error code 1
Storing complete log in /home/vagrant/.pip/pip.log

そしてまたエラーがでる。「apt-get install gfortran」を実行。

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

その他

以下の本でも python機械学習が書かれていた。その中では上で記載したモジュールの他にグラフ描画用の matplotlib 、機械学習用の sckit-learn の利用も紹介されていました。試してみよう。


matplotlibインストール方法

ここから、matplotlib-1.3.1.win-amd64-py2.7.exeをダウンロードしてダブルクリックでインストール。

importしみる。エラー出た。 pyparsing やらが必要みたい。

>python
Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 125, in <module>
    raise ImportError("matplotlib requires pyparsing")
ImportError: matplotlib requires pyparsing
>>>

pyparsing をインストールする。
>||
pip install pyparsing 

再度、matplotlib をインポート。上手く行った。

>>> import matplotlib
scikit-learnインストール方法
pip install scikit-learn

windows 32bitの場合はこちらのリンクが参考になるかも(http://qiita.com/mojaie/items/995661f7467ffdb40331

・分析ツール使用方法
http://web-analytics-or-die.org/2013/07/pandas/