gcloudコマンドが使えなくなっていた
きっかけ
ある日、GCP環境にアクセスする必要がありgcloudコマンドを叩いたところ、エラーが出てしまい、全くコマンドが実行できなくなっていることに気づきました。
ちなみに環境はmac os 10.15.7、pyenvにてpythonはpython 3.7.4、python2は2.7.16としている環境です。
>>> gcloud -h
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/Users/takeshimiyajima/.pyenv/versions/2.7.16/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/Users/takeshimiyajima/.pyenv/versions/2.7.16/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/Users/takeshimiyajima/.pyenv/versions/2.7.16/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/Users/takeshimiyajima/.pyenv/versions/2.7.16/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
〜中略〜
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:
/Users/takeshimiyajima/.pyenv/versions/2.7.16/bin/python2
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/
試行錯誤
まずはエラーメッセージどおり、CLOUDSDK_PYTHONを設定してみましたが、全くダメでした。
次にエラーメッセージでググるとmacを使っている人たちがこのエラーに遭遇しているようでした。
解決方法は人によって様々で、一番よく見かけたのはpython2.7の再インストールでした。
pyendにて再インストールしてみても自分の環境では同じエラーが出て続けて進展はありませんでした。
悩ましい・・・
解決
次によく見かけたのはopenssl@1.0.2のライブラリをPATHを適切に設定する方法でしたが、自分の環境にはそもそもopenssl@1.1しか入っていませんでした。
そこでopenssl@1.0.2をなんとかインストールできないかとたどり着いた方法が以下のやり方でした。
wget https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
brew install openssl.rb
これで無事、エラーはなくなりました。良かった。
良かったけど、これ調べるだけで1時間ぐらいかかった・・・
参考
https://medium.com/@smithua/install-openssl-1-0-2t-version-on-macos-7084ac52fa8b