Python
目次
Pythonとは?
スクリプト言語の1つ。(Mac OS X に標準搭載されている。)
- 豊富なライブラリモジュールが魅力?
インストール
モジュールのインストールについて
- python本体とモジュールの整合に注意が必要
- architecture:MacOSX 10.6 標準では, 64 bit (x86_64) の Python 2.6.1 と NumPy 1.3.0 がインストールされるとのこと.
- インストール済みモジュールを調べる
- バージョン(例 numpy)
$ python -c "import numpy;print numpy.__version__" 1.3.0
- architecture(例 math)
$ python -c "import math;print dir(math);import commands;print commands.getoutput('file ' + math.__file__)"
- 調べ方が統一されているわけではない
site-packagesディレクトリ
モジュール情報が収められるディレクトリ
MacOSX 10.5標準pythonでの例
/Library/Python/2.5/site-packages
python-2.5.x.dmgでの例
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/
python本体のインストール
標準搭載版でないpythonをインストール http://www.python.org/download
- python-3.1.x.dmg
- python-2.6.x.dmg
- python-2.5.x.dmg
Python 3.xのインストール
http://www.r-styles.net/mt-archives/weblog/development/python30-on-leopard.html
Pythonを支援する環境・ツール
IPython
python用の対話型シェル環境
- Python標準シェルに比べて高機能
setuptools
一部のモジュールに対して管理機能(インストール等)を提供
- http://pypi.python.org/pypi/setuptools
- easy_installコマンドも提供
- インストール作業例
$ sh setuptools-0.6c11-py2.5.egg
モジュール
SciPy
科学技術計算関数を提供。
- macports からもインストール可能。
SciPyについての説明等:
- http://ja.wikipedia.org/wiki/SciPy
- http://alias.dip.jp/blog/archives/category/research/scipy
- http://scipy.dip.jp/index.php?SciPy
Mac OS X 10.5.7 Leopardへのインストール:http://d.hatena.ne.jp/yamato-y/20090608
- SciPy 0.7 は Python 2.6 をサポート
NumPy
数値計算向け環境 http://docs.scipy.org/doc/numpy/reference/routines.html
- 関数抜粋とMATLAB比較: http://mathesaurus.sourceforge.net/matlab-numpy.html
- NumPy 1.3 は Python 2.6 をサポート
- Mac標準搭載Pythonで利用する場合には → http://radpy.blogspot.com/2009/06/numpymac.html
Matplotlib
2Dプロット環境
Matplotlib Basemap Toolkit
地図とデータをプロット http://matplotlib.sourceforge.net/basemap/doc/html/ http://www.scipy.org/Cookbook/Matplotlib/Maps
coastline データは GSHHS のもの(http://www.soest.hawaii.edu/wessel/gshhs/gshhs.html) . state, country, river データは GMT のもの(http://gmt.soest.hawaii.edu).
- 関連→ リスト/地球科学系
lxml
xml処理.
- "Pythonic binding for the libxml2 and libxslt libraries" とのこと
- http://codespeak.net/lxml
- インストール例
$ curl -O ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz $ curl -O ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz $ curl -O http://codespeak.net/lxml/lxml-2.2.4.tgz $ $ cd libxml2-2.7.6 $ ./configure --prefix=/usr/local/libxml2-2.7.6 $ make $ sudo make install $ cd /Library/Python/2.5/site-packages # for Mac OSX 10.5 default Python $ sudo ln -s /usr/local/libxml2-2.7.6/lib/python2.5/site-packages/* . $ $ cd libxslt-1.1.26 $ ./configure --prefix=/usr/local/libxslt-1.1.26 --with-libxml-prefix=/usr/local/libxml2-2.7.6 $ make $ sudo make install $ cd /Library/Python/2.5/site-packages # for Mac OSX 10.5 default Python $ sudo ln -s /usr/local/libxslt-1.1.26/lib/python2.5/site-packages/* . $ $ STATIC_DEPS=true easy_install $ STATIC_DEPS=true sudo easy_install
obspy
地震計データの処理.http://svn.geophysik.uni-muenchen.de/trac/obspy/wiki/
- インストール例
$ svn checkout https://svn.geophysik.uni-muenchen.de/svn/obspy obspy $ cd obspy $ python >>> import commands >>> list=["",'arclink','core','fissures','gse2','imaging','mseed','sac','seisan','seishub','signal','wav','xseed'] >>> for x in list: >>> if x != "": x = '.' + x >>> commands.getoutput('(cd obspy' + x + '/trunk; python setup.py develop)')
PyOpenGL
OpenGL for Python http://sourceforge.net/projects/pyopengl/
- インストール例
$ tar xvzf PyOpenGL-3.0.1b1.tar.gz $ cd PyOpenGL-3.0.1b1 $ python setup.py install
- テスト例
globe.py (minimum spanning tree on a sphere)を試す. http://www.treedub.org/blog/wp-content/uploads/2007/09/globe.tar.gz
$ python globe.py 20
関連情報
Wiki内
- PythonTips
- リスト/開発ツール
- リスト/UNIXパッケージ/Python
- 共有コード
Wiki外
Pythonについての情報