2

I had some system updates for my manjaro installation and after that I get the following error message when trying to run gcloud:

gcloud components update
Traceback (most recent call last):
  File "/home/mani/Downloads/google-cloud-sdk/lib/gcloud.py", line 104, in <module>
    main()
  File "/home/mani/Downloads/google-cloud-sdk/lib/gcloud.py", line 62, in main
    from googlecloudsdk.core.util import encoding
  File "/home/mani/Downloads/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
    from googlecloudsdk.core.util import importing
  File "/home/mani/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
    import imp
  File "/usr/lib/python3.9/imp.py", line 23, in <module>
    from importlib import util
  File "/usr/lib/python3.9/importlib/util.py", line 2, in <module>
    from . import abc
  File "/usr/lib/python3.9/importlib/abc.py", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/usr/lib/python3.9/typing.py", line 26, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/usr/lib/python3.9/re.py", line 124, in <module>
    import enum
  File "/home/mani/Downloads/google-cloud-sdk/lib/third_party/enum/__init__.py", line 26, in <module>
    spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'

After looking online I found that the problem could be that this version of gcloud doesn't support python3.9 and the recommended solution was to run gcloud components update but that gives the same error. Is there a way I could revert or make the command use an older python version to upgrade itself then go back to the new python 3.9?

mani
  • 45
  • 5
  • 1
    Does this answer your question? [AttributeError: module 'importlib' has no attribute 'util'](https://stackoverflow.com/questions/64010263/attributeerror-module-importlib-has-no-attribute-util) – jabbson Jan 08 '21 at 14:35
  • @jabbson Yeah I actually read that then tried the command and it didn't work but now I see that they also included a way to tell `gcloud` to use older python. Thanks – mani Jan 08 '21 at 23:17

1 Answers1

0

As per following GCP official document you can restore your Cloud Shell VM to it's original state by removing the home directory as follows:

ls -a $HOME

sudo rm -rf $HOME

Now in the Cloud Shell click on the three dot menu and restart the VM will create an new VM and home directory will be restore as it's default state.

As you have the issue in your local machine, after researching I have noticed following PIT1 as a bug in Google Issue Tracker. There are few WA for now on the following thread you can apply it accordingly.

There is another PIT2 as a Feature request to add support for python 3.9. Feel free to post there should you have any additional comments or concerns regarding the issue.

Another WA found in the github might be useful for your use case.

Mahboob
  • 1,877
  • 5
  • 19