手軽に科学技術計算のためにWindowsでPython を始めたい人へ。( 計算環境構築編 )
先日windowsの方にcygwinを入れてpythonを動かせる環境を作りました。
Windowsにpython環境をインストールする方法 - Hope is a Dream. Dream is a Hope.
目的はこのため
1. 科学技術計算のために Python を始めよう。 — Scipy lecture notes
pythonパッケージ管理のインストール
setuptoolsのインストール
cygwinのsetup.exe
からしても良いのですが
折角なのでapt-cygでインストールします
apt-cyg install setuptools
$ easy_install --version
distribute 0.6.34
これでeasy_installを使えるようになります。 (後で使います)
pipのインストール
$ easy_install pip
$ pip --version
pip 1.5.6 from /usr/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
参考 http://chiranoura.nobody.jp/articles/2014-05-27_01_how_to_install_pip_and_setuptools/
計算環境の準備
Numpyのインストール
cygwin上で
apt-cyg find Numpy
>>
Searching for installable packages matching numpy:
python-numpy
python-numpy-debuginfo
python3-numpy
python3-numpy-debuginfo
今回はpython27を使っているので、python-numpy
をインストールします。
apt-cyg install python-numpy
インストールが完了したらpython
を起動して確認して見ましょう。
python
>>> import numpy
できましたでしょうか?
僕はエラーがでたので環境を少しいじりました。
http://centilemma.com/windows/cygwin.html
# repair lapack_file
$ cp /usr/lib/lapack/cygblas-0.dll /usr/bin
$ cp /usr/lib/lapack/cyglapack-0.dll /usr/bin
$ # check
$ cygcheck /lib/python2.7/site-packages/numpy/linalg/lapack_lite.dll
numpyをimportできるか確認してみます。
$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.7.2'
>>> numpy.__file__
'/usr/lib/python2.7/site-packages/numpy/__init__.pyc'
>>> quit()
できました。
Scipyのインストール
おもむろに
apt-cyg find scipy
ない。
しょうがないのでインストーラーを落としてくるが。
http://www.lfd.uci.edu/~gohlke/pythonlibs/
ダウンロードしたのはこちら
scipy-0.14.0.win32-py2.7.exe
pythonが32版なのでとりあえずこちらを試して見ます。
cd {scipy-0.14.0.win32-py2.7.exeがある場所}
easy_install scipy-0.14.0.win32-py2.7.exe
$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> scipy.__version__
'0.14.0'
>>> scipy.__file__
'/usr/lib/python2.7/site-packages/scipy-0.14.0-py2.7-cygwin-1.7.33-i686.egg/scipy/__init__.pyc'
>>> quit()
一応環境はできたので、今回は実際にサンプルをまわして行きます。
Matplotlibのインストール
apt-cyg install matplotlib
ない!
またソースを落とす。
http://www.lfd.uci.edu/~gohlke/pythonlibs/
はじめからソースを落として置けば良かった。
cd {matplotlib-1.4.2.win32-py2.7.exeがある場所}
easy_install matplotlib-1.4.2.win32-py2.7.exe
$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'1.4.2'
>>> matplotlib.__file__
'/usr/lib/python2.7/site-packages/matplotlib-1.4.2-py2.7-cygwin-1.7.33-i686.egg/matplotlib/__init__.pyc'
>>> quit()
iPython
easy_install ipython
演算用のフォルダを作成
まずは仮にcygwinフォルダの中に
サンプルコード用のフォルダを作ります
cygwin/home/<ユーザ>/pytest
pythonを起動して, scipy
のfftpack
を呼んで見る
$ python
Python 2.7.8 (default, Jul 28 2014, 01:34:03)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy import fftpack
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/scipy-0.14.0-py2.7-cygwin-1.7.33-i686.egg/scipy/fftpack/__init__.py", line 97, in <module>
from .basic import *
File "/usr/lib/python2.7/site-packages/scipy-0.14.0-py2.7-cygwin-1.7.33-i686.egg/scipy/fftpack/basic.py", line 12, in <module>
from . import _fftpack
File "/usr/lib/python2.7/site-packages/scipy-0.14.0-py2.7-cygwin-1.7.33-i686.egg/scipy/fftpack/_fftpack.py", line 7, in <module>
__bootstrap__()
File "/usr/lib/python2.7/site-packages/scipy-0.14.0-py2.7-cygwin-1.7.33-i686.egg/scipy/fftpack/_fftpack.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: Permission denied
。。。。
失敗。
分からない。
パーミッションエラーが発生している。
matplotlibも同様のエラーなので、cygwinの方の設定かもしれない。
こちらを参考にしてすすめていこう。
http://ftablog.s56.xrea.com/index.php?itemid=197
追記
完全版を追加しました。