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

## 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hayashier.gitbook.io/article/aws/awscli-versionup-error.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
