AWS CLI バージョンアップでエラー発生を解消

$ pip install awscli --upgrade --user
:
OSError: [Errno 13] Permission denied: '/Users/hayshogo/Library/Python/2.7/lib'

pipのインストールでエラー

$ sudo easy_install pip
TEST FAILED: /lib/python2.7/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
$ cat ~/.pydistutils.cfg 
[install]
prefix=

空のprefixを.pydistutils.cfgで定義したのでこれを除去

$ rm ~/.pydistutils.cfg                                       
$ sudo easy_install pip                                    
$ aws -v
:
ImportError: No module named colorama

HomeBrewでインストールしたPython削除

$ brew uninstall python

デフォルトでインストールされているPythonが使われていることを確認

$ python --version
Python 2.7.10
$ which python
/usr/bin/python

PyenvでPythonをインストール

$ brew install pyenv-virtualenv
$ vim ~/.zshrc

以下を追記

export PYENV_ROOT=${HOME}/.pyenv
if [ -d "${PYENV_ROOT}" ]; then
    export PATH=${PYENV_ROOT}/bin:$PATH
    eval "$(pyenv init -)"
    eval "$(pyenv virtualenv-init -)"
fi
$ source ~/.zshrc

Pythonのバージョンをインストール

$ pyenv install -l
Available versions:
  2.1.3
  2.2.3
  2.3.7
:
:
  stackless-3.4.7
  stackless-3.5.4
$ pyenv versions
$ pyenv install 2.7.14
$ pyenv install 3.6.4
$ pyenv versions
* system (set by /Users/hayshogo/.pyenv/version)
  2.7.14
  3.6.4

目的のPythonのバージョンに切り替え

$ pyenv global 2.7.14
$ python -V
Python 2.7.14
$ pip uninstall pip
$ easy_install pip
$ pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
$ pip uninstall awscli
$ aws --version
zsh: /usr/local/bin/aws: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
$ pip install awscli --upgrade --user
OSError: [Errno 13] Permission denied: '/Users/hayshogo/Library/Python/2.7/lib'
$ pip install awscli
$ aws --version
aws-cli/1.14.53 Python/2.7.14 Darwin/16.7.0 botocore/1.9.6

通常は以下のようにアップグレード可能

$ sudo -H pip install -U pip
$ sudo -H pip install -U awscli
$ aws --version
aws-cli/1.16.67 Python/2.7.15 Darwin/16.7.0 botocore/1.12.57

参考

  • Permission denied: ‘/Library/Python/2.7/site-packages/pync/vendor’ https://github.com/sindresorhus/weechat-notification-center/issues/1
  • Pythonインストール(Mac編) https://qiita.com/ms-rock/items/6e4498a5963f3d9c4a67

My Twitter & RSS

Leave a Reply

Your email address will not be published. Required fields are marked *