LoginSignup
9
2

More than 5 years have passed since last update.

Google Cloud SDK のインストール時に UnicodeDecodeError が出た時の対応

Last updated at Posted at 2018-07-26

環境

  • macOS 10.13.4
  • Python 2.7.14

現象

Google Cloud SDK ドキュメント  |  Cloud SDK  |  Google Cloud

を参考にダウンロードしたアーカイブを展開し、そのディレクトリで

% ./google-cloud-sdk/install.sh

を実行したところ次のエラーが出ました。

The Google Cloud SDK installer will now prompt you to update an rc
file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use
[/Users/katsuhiko.yoshida/.zshrc]:
Traceback (most recent call last):
  File "/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 218, in <module>
    main()
  File "/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 203, in main
    sdk_root=bootstrapping.SDK_ROOT,
  File "/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 452, in UpdateRC
    completion_update, path_update, rc_path, sdk_root, host_os).Update()
  File "/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 214, in Update
    self.path, rc_contents, source_line=self._GetSourceLine())
  File "/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/platforms_install.py", line 165, in _GetRcContents
    filtered_contents = subre.sub('', rc_contents)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 2: ordinal not in range(128)

対応

再度

% ./google-cloud-sdk/install.sh

を実行し、

Enter a path to an rc file to update, or leave blank to use
[/Users/katsuhiko.yoshida/.zshrc]:

が表示された時に /Users/katsuhiko.yoshida/.zshrc.gcloud のように(存在しない)新規ファイルを入力します。

インストール処理が完了すると先程入力したファイル(/Users/katsuhiko.yoshida/.zshrc.gcloud)に次の様な内容が出力されています。

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/path.zsh.inc' ]; then source '/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/completion.zsh.inc' ]; then source '/Users/katsuhiko.yoshida/Downloads/google-cloud-sdk/completion.zsh.inc'; fi
k

これをシェルの設定ファイル(上記の例だと /Users/katsuhiko.yoshida/.zshrc)に追記します。

設定の反映をします。

% source /Users/katsuhiko.yoshida/.zshrc

最後に不要になったファイルを削除して完了です。

% rm /Users/katsuhiko.yoshida/.zshrc.gcloud

原因(仮説)

恐らく設定ファイル内に存在する日本語文字列のデコードに失敗したのではないかと思います。ただし、これ以降再現しなくなってしまったため、間違っているかもしれません。

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2