easy_install と PEP8
良いコードを書く技術っていう本を読んでます。
各言語のコーディング標準には目を通しておくとよいということで、
PEP8を読んでみたら、まぁ色々と標準スタイルから外れてることをしてる。。。
毎回毎回コードを書く時にPEP8を見ていると覚えるんだろうけど、
正直それもちょっとって思っていたら、PEP8に従っているかどうかチェックしてくれるモジュールがあるらしい。
easy_installっていうパッケージ管理システムを使ってインストールするようなので、
ひとつずつインストールしてやってみよう。
virtual_python
早速ということで、ez_install.pyをダウンロードしてきてセットアップ開始とやってみたら、
権限無いから駄目よんって怒られた。
[kobakoba0723@fedora13-intel64 ~]$ python ez_setup.py Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/usr/lib/python2.6/site-packages/test-easy-install-2476.write-test' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /usr/lib/python2.6/site-packages/ Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable. For information on other options, you may wish to consult the documentation at: http://peak.telecommunity.com/EasyInstall.html Please make the appropriate changes for your system and try again. [kobakoba0723@fedora13-intel64 ~]$
rootになって突っ込んでしまえば良いかなぁとも思ったんだけど、virtual_pythonっていうものがあることを知った。
ローカル環境にPythonの環境を構築できるようにしてくれる便利なツール。
[kobakoba0723@fedora13-intel64 ~]$ python2.6 virtual-python.py Creating /home/kobakoba0723/lib/python2.6 Creating /home/kobakoba0723/lib/python2.6/site-packages Creating /home/kobakoba0723/include/python2.6 Copying /usr/bin/python2.6 to /home/kobakoba0723/bin You're now ready to download ez_setup.py, and run /home/kobakoba0723/bin/python ez_setup.py [kobakoba0723@fedora13-intel64 ~]$
何事も無くセットアップが出来たの引き続きeasy_installのセットアップに。
# 実行ログを見てると、「ez_setup.pyの実行どうぞどうぞ」ってなってる。
# ダウンロード元も同じところだし、ez_setup.pyのためにvirtual_python.pyって出来たのかな
easy_install
続いてez_setup.pyを実行してeasy_installを使えるようにする。
[kobakoba0723@fedora13-intel64 ~]$ /home/kobakoba0723/bin/python ez_setup.py Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/usr/lib/python2.6/site-packages/test-easy-install-2506.write-test' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /usr/lib/python2.6/site-packages/ Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable. For information on other options, you may wish to consult the documentation at: http://peak.telecommunity.com/EasyInstall.html Please make the appropriate changes for your system and try again. [kobakoba0723@fedora13-intel64 ~]$
あらま、エラーが。。。さっきと同じだ、権限無いから駄目よんって
どうやらモジュール追加用の設定が正しくないらしい。
どうしたもんかなぁと思って、うろうろしてたら.pydistutils.cfgっていうファイルを作れば良いらしいので、
自分の環境に合わせて以下で作成
[install] install_lib = ~/lib/python2.6/site-packages install_scripts = ~/bin
これで大丈夫かなぁ*1と、ドキドキしながら再実行
[kobakoba0723@fedora13-intel64 ~]$ /home/kobakoba0723/bin/python ez_setup.py Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg TEST FAILED: /home/kobakoba0723/lib/python2.6/site-packages/ does NOT support .pth files error: bad install directory or PYTHONPATH You are attempting to install a package to a directory that is not on PYTHONPATH and which Python does not read ".pth" files from. The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /home/kobakoba0723/lib/python2.6/site-packages/ and your PYTHONPATH environment variable currently contains: '' Here are some of your options for correcting the problem: * You can choose a different installation directory, i.e., one that is on PYTHONPATH or supports .pth files * You can add the installation directory to the PYTHONPATH environment variable. (It must then also be on PYTHONPATH whenever you run Python and want to use the package(s) you are installing.) * You can set up the installation directory to support ".pth" files by using one of the approaches described here: http://peak.telecommunity.com/EasyInstall.html#custom-installation-locations Please make the appropriate changes for your system and try again. [kobakoba0723@fedora13-intel64 ~]$
どうもPYTHONPATHの設定が出来てないのが良くないらしいので、.bash_profileに設定
ついでに、PATHの順番を変えて、$HOME/binを先に持ってくる。
PYTHONPATHは、$HOME//lib/python2.6/site-packages/で設定
[kobakoba0723@fedora13-intel64 ~]$ source .bash_profile [kobakoba0723@fedora13-intel64 ~]$ python Python 2.6.4 (r264:75706, Apr 1 2010, 02:55:51) [GCC 4.4.3 20100226 (Red Hat 4.4.3-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/home/kobakoba0723/lib/python2.6/site-packages', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib64/python2.6/site-packages/gtk-2.0', '/usr/lib/python2.6/site-packages'] >>>
ちゃんとsys.pathにローカルのsite-packagesが設定されてる。
今度は大丈夫かな。。。
[kobakoba0723@fedora13-intel64 ~]$ python ez_setup.py Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg Creating /home/kobakoba0723/lib/python2.6/site-packages/site.py Processing setuptools-0.6c11-py2.6.egg Copying setuptools-0.6c11-py2.6.egg to /home/kobakoba0723/lib/python2.6/site-packages Adding setuptools 0.6c11 to easy-install.pth file Installing easy_install script to /home/kobakoba0723/bin Installing easy_install-2.6 script to /home/kobakoba0723/bin Installed /home/kobakoba0723/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg Processing dependencies for setuptools==0.6c11 Finished processing dependencies for setuptools==0.6c11 [kobakoba0723@fedora13-intel64 ~]$
よし、出来た^^
なんやかんやで2時間以上経過。。。
最初からrootでやっときゃこんなに時間はかからんかったんだろうなぁと思いながらも、
try&errorで色々出来たことは自分のためになってるはず。
次からセットアップする時はここを見れば良いわけだし。
pep8のインストール
easy_installを使ってpep8のインストール
[kobakoba0723@fedora13-intel64 ~]$ easy_install pep8 Searching for pep8 Reading http://pypi.python.org/simple/pep8/ Reading http://github.com/cburroughs/pep8.py/tree/master Reading http://github.com/jcrocholl/pep8 Best match: pep8 0.6.1 Downloading http://pypi.python.org/packages/source/p/pep8/pep8-0.6.1.tar.gz#md5=49380cdf6ba2e222e8630cb0afe29d66 Processing pep8-0.6.1.tar.gz Running pep8-0.6.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-sXtRm5/pep8-0.6.1/egg-dist-tmp-h_lt1n Adding pep8 0.6.1 to easy-install.pth file Installing pep8 script to /home/kobakoba0723/bin Installed /home/kobakoba0723/lib/python2.6/site-packages/pep8-0.6.1-py2.6.egg Processing dependencies for pep8 Finished processing dependencies for pep8 [kobakoba0723@fedora13-intel64 ~]$
何事もなく無事にインストール完了、どうも~/binにインストールされるみたい。
pep8に従ってるかチェックチェック
さてさて、やっと本題のPEP8でのチェック。
# そもそもモジュールファイルの名前からしてルール通りじゃないから、中身なんてどうなることやら。。。
[kobakoba0723@fedora13-intel64 TestTool]$ pep8 getLogFile.py getLogFile.py:15:1: E302 expected 2 blank lines, found 1 getLogFile.py:16:3: E111 indentation is not a multiple of four getLogFile.py:20:80: E501 line too long (95 characters) getLogFile.py:35:1: W293 blank line contains whitespace getLogFile.py:38:3: E303 too many blank lines (2) getLogFile.py:58:69: W291 trailing whitespace getLogFile.py:67:100: E225 missing whitespace around operator getLogFile.py:76:44: E201 whitespace after '(' getLogFile.py:124:58: E231 missing whitespace after ',' [kobakoba0723@fedora13-intel64 TestTool]$
。。。やっぱりいっぱい出たなぁ。
こうやって間違ってることを押してくれるとありがたい。
さてせっせと直して、またpep8にチェックしてもらうかな。
良いコードを書く技術 ?読みやすく保守しやすいプログラミング作法 (WEB+DB PRESS plus)
- 作者: 縣俊貴
- 出版社/メーカー: 技術評論社
- 発売日: 2011/04/09
- メディア: 単行本(ソフトカバー)
- 購入: 46人 クリック: 2,459回
- この商品を含むブログ (68件) を見る