環境
OS
$ cat /etc/redhat-release CentOS release 5.5 (Final)
python
2.4.3がインストール済み
$ rpm -qa | grep python-2 python-2.4.3-27.el5_5.3 libxml2-python-2.6.26-2.1.2.8.el5_5.1
目的
- 本番環境で動作しているサーバでAWSを操作する要件が出たので、AWS CLIを導入する。
- AWS CLI を使用するために
Python 2.6.3
以上が必要だが、元々インストールされているバージョンが2.4.3
のため、現状の動作に影響を与えないようにpython 2.6.9
を導入する。
方法
既存の動作に影響を与えず上位のバージョンのpythonを導入するためpyenv
を使用。
導入については以下を参考に。
pyenvの使い方とインストール - Python入門から応用までの学習サイト
今回は、バージョン検証のためではないため、どのユーザでも参照できるように/usr/local
にpyenvを導入する。
pyenv実行に必要なパッケージ取得
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel -y
Common build problems · pyenv/pyenv Wiki · GitHub
pyenv取得
$ cd /usr/local $ git clone https://github.com/yyuu/pyenv.git
環境変数設定
$ echo 'export PYENV_ROOT="/usr/local/pyenv"' >> /usr/local/pyenv/.pyenv_profile $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> /usr/local/pyenv/.pyenv_profile $ echo 'eval "$(pyenv init -)"' >> /usr/local/pyenv/.pyenv_profile $ source /usr/local/pyenv/.pyenv_profile
インストールリスト表示
pyenv install -l
python2.6.9インストール
$ pyenv install 2.6.9 Downloading Python-2.6.9.tgz... -> https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tgz Installing Python-2.6.9... patching file setup.py Hunk #1 succeeded at 354 (offset 9 lines). patching file ./configure patching file ./Modules/readline.c Hunk #1 succeeded at 199 (offset -7 lines). Hunk #2 succeeded at 705 (offset -44 lines). Hunk #3 succeeded at 852 (offset -7 lines). Hunk #4 succeeded at 855 with fuzz 2 (offset -63 lines). patching file ./setup.py Hunk #1 succeeded at 1698 (offset 23 lines). patching file ./Lib/ssl.py patching file ./Modules/_ssl.c WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib? WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib? Installing pip from https://bootstrap.pypa.io/get-pip.py... Installed Python-2.6.9 to /usr/local/pyenv/versions/2.6.9
以下が出た場合はコンパイラが無いので yum install gcc -y
を実行
configure: error: no acceptable C compiler found in $PATH
インストール確認
$ pyenv versions * system (set by /usr/local/pyenv/version) 2.6.9
利用バージョン変更
$ python -V Python 2.4.3 $ pyenv global 2.6.9 $ pyenv versions system * 2.6.9 (set by /usr/local/pyenv/version) $ python -V Python 2.6.9
pipインストール
$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1558k 100 1558k 0 0 3879k 0 --:--:-- --:--:-- --:--:-- 5665k $ python get-pip.py DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6 Requirement already up-to-date: pip in ./.pyenv/versions/2.6.9/lib/python2.6/site-packages $ which pip ~/pyenv/shims/pip
既に入ってた。
awscliインストール
$ pip install awscli $ which aws ~/.pyenv/shims/aws
メモ
pythonの仕組み
virtualenv - def __mopemope__(self, *args, **kwargs):
pythonは自分自身のパスの上位のlib/pythonx.xをライブラリとして認識する。
$ which python /usr/bin/python $ ls -l /usr/bin/python -rwxr-xr-x 2 root root 8304 11月 12 2010 /usr/bin/python $ ls -ld /usr/lib/python2.4/ drwxr-xr-x 3 root root 4096 11月 12 2010 /usr/lib/python2.4/
読み込んでるライブラリのパス
$ /usr/bin/python -c "import sys;print sys.path" ['', '/usr/lib/python2.4/site-packages/simplejson-2.1.2-py2.4.egg', '/usr/lib/python2.4/site-packages/jsontools-0.1-py2.4.egg', '/usr/lib64/python24.zip', '/usr/lib64/python2.4', '/usr/lib64/python2.4/plat-linux2', '/usr/lib64/python2.4/lib-tk', '/usr/lib64/python2.4/lib-dynload', '/usr/lib64/python2.4/site-packages', '/usr/lib64/python2.4/site-packages/Numeric', '/usr/lib64/python2.4/site-packages/gtk-2.0', '/usr/lib/python2.4/site-packages']