dorivenの日記

気がついたら社会人。気になる技術的なことについて少しずつ書いていけたらと思っております。

S3cmdのインストール時にエラーで躓いていた件

AWSの知識が必要ということで個人的に色々とお勉強している最中なんだけど、S3をターミナルで操作できるs3cmdをインストールした後に詰まったのでメモ。

環境

使用したサーバはEC2のAmazonLinuxAMIから作成したもので、あまりカスタマイズしていないデフォルト仕様に近いもの。

エラーの内容

Problem: ImportError: No module named S3.ExitCodes
S3cmd:   unknown version. Module import problem?
python:   2.7.9 (default, Mar  4 2015, 20:43:00)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)]
environment LANG=ja_JP.UTF-8

Traceback (most recent call last):
  File "/usr/bin/s3cmd", line 2528, in <module>
    from S3.ExitCodes import *
ImportError: No module named S3.ExitCodes

Your sys.path contains these entries:
	/usr/bin
	/usr/lib64/python27.zip
	/usr/lib64/python2.7
	/usr/lib64/python2.7/plat-linux2
	/usr/lib64/python2.7/lib-tk
	/usr/lib64/python2.7/lib-old
	/usr/lib64/python2.7/lib-dynload
	/usr/local/lib64/python2.7/site-packages
	/usr/local/lib/python2.7/site-packages
	/usr/lib64/python2.7/site-packages
	/usr/lib/python2.7/site-packages
	/usr/lib64/python2.7/dist-packages
	/usr/lib64/python2.7/dist-packages/PIL
	/usr/lib/python2.7/dist-packages
Now the question is where have the s3cmd modules been installed?

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    An unexpected error has occurred.
  Please try reproducing the error using
  the latest s3cmd code from the git master
  branch found at:
    https://github.com/s3tools/s3cmd
  If the error persists, please report the
  above lines (removing any private
  info as necessary) to:
   s3tools-bugs@lists.sourceforge.net
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

python触ったことなかったのでエラーが出ると見なかったことにしようとする自分の悪い癖が出た。
結局、一番上に書いてあるS3のパッケージが読み込めてないことが問題だった。

解決方法

pythonのことはよく分からないので、ライブラリの追加方法とかググる

解決策としては二点あり、

  1. デフォルトのライブラリパスに追加
  2. コード内でライブラリパスの追加

今回は.2のやり方で対策。(1のやり方はpython日頃から触っている人だったらわかるだろうし)

以下のコードを先頭にあるimport sysの下に追加しておしまい

sys.path.append("/usr/lib/python2.6/site-packages")

おわりに

これってpythonを触ってた人ならこんな事じゃ躓かないんだろうな〜って思ったり。