created: 2021-01-27T03:06:06.000Z

[gcloud] module 'importlib' has no attribute 'util'


$ gcloud components update
Traceback (most recent call last):
  File "/Users/mossan/google-cloud-sdk/lib/", line 104, in <module>
  File "/Users/mossan/google-cloud-sdk/lib/", line 62, in main
    from googlecloudsdk.core.util import encoding
  File "/Users/mossan/google-cloud-sdk/lib/googlecloudsdk/", line 23, in <module>
    from googlecloudsdk.core.util import importing
  File "/Users/mossan/google-cloud-sdk/lib/googlecloudsdk/core/util/", line 23, in <module>
    import imp
  File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/", line 23, in <module>
    from importlib import util
  File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/", line 2, in <module>
    from . import abc
  File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/", line 26, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/", line 124, in <module>
    import enum
  File "/Users/mossan/google-cloud-sdk/lib/third_party/enum/", line 26, in <module>
    spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'


To enable gcloud to work with Python 2.7.x as well as Python 3+ a shim was introduced to enable the enum module years ago. This shim breaks with Python 3.9 because of this commit, it looks like the root cause has already been removed in commit which looks to be scheduled to be released in Python 3.10.



gcloudをアップグレードするためのgcloudコマンドを動かすために CLOUDSDK_PYTHON=python2 をつけて古いpythonを使って実行できるようにする。

$ CLOUDSDK_PYTHON=python2 gcloud components update
[ad] 人を伸ばす力―内発と自律のすすめ
エドワード・L. デシ, リチャード フラスト (単行本)