Rubyと筋肉とギターとわたし

筋トレが仕事です

【gcloud】Python3.8に対応したgcloudコマンドをインストールしたい

どうもてぃ。

久々にブログ書きます。

以前インストールしたgcloudコマンドがpython 2.7に依存するもので、gcloudコマンドを使用するたび毎回pythonのバージョンを切り替えるのクソだるかったためバージョンアップしました。

環境

% lsb_release -a
No LSB modules are available.
Distributor ID: LinuxMint
Description:    Linux Mint 19.3 Tricia
Release:    19.3
Codename:   tricia

% python -V
Python 3.8.1

やったこと

とりあえず公式にのっとって再インストールする

cloud.google.com

初期化

インストールが一通り終わったのでgcloud init

% gcloud init
ERROR: gcloud failed to load: No module named '_sqlite3'
    gcloud_main = _import_gcloud_main()
    import googlecloudsdk.gcloud_main
    from googlecloudsdk.calliope import cli
    from googlecloudsdk.calliope import backend
    from googlecloudsdk.calliope import parser_extensions
    from googlecloudsdk.core.updater import update_manager
    from googlecloudsdk.core.updater import installers
    from googlecloudsdk.core.credentials import store
    from googlecloudsdk.core.credentials import creds as c_creds
    import sqlite3
    from sqlite3.dbapi2 import *
    from _sqlite3 import *

This usually indicates corruption in your gcloud installation or problems with your Python interpreter.

Please verify that the following is the path to a working Python 2.7 or 3.5+ executable:
    /home/motty/.asdf/installs/python/3.8.1/bin/python3

If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 or 3.5+ executable.

If you are still experiencing problems, please reinstall the Cloud SDK using the instructions here:
    https://cloud.google.com/sdk/
~ 

ぱっとみsqlite3が入ってないから起こってるっぽい。

対応

確かpythonはその時の状態でビルドされるため、aptsqlite関連のパッケージをインストールしたとしてもpython自体に反映されないはず。

なので、念の為aptで入れた後、pythonをインストールし直す。

ちなみに自分は言語系はasdfで管理しています。

% sudo apt-get install libsqlite3-dev libbz2-dev libncurses5-dev libgdbm-dev liblzma-dev libssl-dev tcl-dev tk-dev libreadline-dev

% asdf uninstall python 3.8.1

% asdf install python 3.8.1

かんりょぉぉおおおおおおおおおおおおお

うまくいったぜ

% gcloud init

Welcome! This command will take you through the configuration of gcloud.

Settings from your current configuration [default] are:
core:
  account: hogehogehogehoge@hoge.com
  disable_usage_reporting: 'True'
  project: hogehogehoge

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings 
 [2] Create a new configuration
Please enter your numeric choice:  

pythonのエラー関連は割りかしハマりますね。

とりあえずgcloudコマンドがアップグレード出来てよかった。