2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cloud SDKで使われているPythonのバージョンを確認する

Last updated at Posted at 2020-01-11

はじめに

なんだかんだでPython 3への移行準備が進んでる感じがありますね。
お客さんによってはPython 3を使用するようにしたエビデンスを求められることもあると思うので、現状使用しているバージョンを確認する方法を書いておきます。

確認方法

確認環境はDockerのUbuntu18.04を使用しています。

今回は gcloud コマンドを例に記載しますが、各コマンド(bqやらgsutilやらgcloudやら)毎に実行しているスクリプトが違う為、必要であればその都度別途調べるしかないです。

対象のコマンドの場所を調べる

root@0ec7cd4678a7:~# which gcloud
/root/google-cloud-sdk/bin/gcloud

対象のスクリプト(コマンド)を書き換える

/root/google-cloud-sdk/bin/gcloud
...
# 最終行をコメントアウト
# exec "$CLOUDSDK_PYTHON" $CLOUDSDK_PYTHON_ARGS "${CLOUDSDK_ROOT_DIR}/lib/gcloud.py" "$@"
# 追加
exec "$CLOUDSDK_PYTHON" --version

実行

root@0ec7cd4678a7:~# gcloud 
Python 2.7.17

おまけ(CLOUDSDK_PYTHONにpython3を設定する)

root@0ec7cd4678a7:~# ls -1 /usr/bin/python*
/usr/bin/python
/usr/bin/python2
/usr/bin/python2.7
/usr/bin/python3
/usr/bin/python3.6
/usr/bin/python3.6m
/usr/bin/python3m
root@0ec7cd4678a7:~# export CLOUDSDK_PYTHON=python3
root@0ec7cd4678a7:~# gcloud 
Python 3.6.9

はい

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?