はてブロ@ama_ch

https://twitter.com/ama_ch

easy_installが激しく便利

PythonでHTTP周りのあれこれがしたくて調べていたら発見したmechanizeというモジュールを使いたくなって、ダウンロードしようと探していたら、easy_installという便利なモジュールがあるらしい。
こいつがあると、

easy_install モジュール名

とやるだけで勝手に探してきてインストールしてくれるらしい。すげー!


なので、早速インストールしてみました。
EasyInstall - The PEAK Developers' Centerでダウンロードできるけど、コマンドを使うのが簡単なのでそちらでやってみましょう。

$ curl -O http://peak.telecommunity.com/dist/ez_setup.py

これでeasy_installの本体をダウンロードします。Macだと最初からwgetが入っていないので、代わりにcurlコマンドを使います。-Oオプションで、対象をファイルに保存します。

$ python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c8-py2.5.egg
Processing setuptools-0.6c8-py2.5.egg
Copying setuptools-0.6c8-py2.5.egg to /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
Removing setuptools 0.6c7 from easy-install.pth file
Adding setuptools 0.6c8 to easy-install.pth file
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.5/bin
Installing easy_install-2.5 script to /Library/Frameworks/Python.framework/Versions/2.5/bin

Installed /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg
Processing dependencies for setuptools==0.6c8
Finished processing dependencies for setuptools==0.6c8

ダウンロードしたモジュールを実行。無事インストールできたっぽいですね。


ちょっと確認してみましょう。

$ easy_install
error: No urls, filenames, or requirements specified (see --help)

お、command not foundにならずにエラーが出たということは、ちゃんとインストールされましたね!


では目当てのmechanizeをインストールしてみましょう。

$ easy_install mechanize
Searching for mechanize
Reading http://pypi.python.org/simple/mechanize/
Reading http://wwwsearch.sourceforge.net/mechanize/
Best match: mechanize 0.1.7b
Downloading http://wwwsearch.sourceforge.net/mechanize/src/mechanize-0.1.7b.zip
Processing mechanize-0.1.7b.zip
Running mechanize-0.1.7b/setup.py -q bdist_egg --dist-dir /var/folders/7L/7L+o+TYFGjqQStAi1iHKv++++TI/-Tmp-/easy_install-KX69-j/mechanize-0.1.7b/egg-dist-tmp-sOVb5r
warning: no files found matching '0.1.0-changes.txt'
no previously-included directories found matching 'docs-in-progress'
Adding mechanize 0.1.7b to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-0.1.7b-py2.5.egg
Processing dependencies for mechanize
Searching for ClientForm==dev,>=0.2.6
Reading http://pypi.python.org/simple/ClientForm/
Reading http://wwwsearch.sourceforge.net/ClientForm/
Best match: ClientForm 0.2.7
Downloading http://wwwsearch.sourceforge.net/ClientForm/src/ClientForm-0.2.7.zip
Processing ClientForm-0.2.7.zip
Running ClientForm-0.2.7/setup.py -q bdist_egg --dist-dir /var/folders/7L/7L+o+TYFGjqQStAi1iHKv++++TI/-Tmp-/easy_install-cZc8G2/ClientForm-0.2.7/egg-dist-tmp-BiFc79
Adding ClientForm 0.2.7 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ClientForm-0.2.7-py2.5.egg
Finished processing dependencies for mechanize

モジュールをインポートできるか確認します。

>>> import mechanize
>>> help(mechanize)
Help on package mechanize:

NAME
    mechanize

FILE
    /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/mechanize-
0.1.7b-py2.5.egg/mechanize/__init__.py

PACKAGE CONTENTS
    _auth
    _beautifulsoup
以下略!

できたできた!こんなにお手軽にできるんだなぁ、本当に便利!
Python使い必携のツールですね!