9

I tried to install Google Cloud SDK, on macOS, but it shows following error. Can anyone help please?

"Welcome to the Google Cloud SDK!
Traceback (most recent call last):
  File "/Users/kaab/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
    import bootstrapping
  File "/Users/kaab/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 46, in <module>
    from googlecloudsdk.core.updater import update_manager
  File "/Users/kaab/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 39, in <module>
    from googlecloudsdk.core.console import progress_tracker
  File "/Users/kaab/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 651, in <module>
    class _BaseStagedProgressTracker(collections.Mapping):
AttributeError: module 'collections' has no attribute 'Mapping'"
Dronir
  • 866
  • 7
  • 10
Khan
  • 121
  • 1
  • 1
  • 4

1 Answers1

35

Are you running Python 3.10 or newer? Switch to an older Python version. As of now, Cloud SDK officially suggests Python 3.5 to 3.8 and uses a feature that was finally deprecated in 3.10.

When I import from collections import Mapping in Python 3.9, I get the message:

<stdin>:1: DeprecationWarning: Using or importing the ABCs
  from 'collections' instead of from 'collections.abc' is deprecated
  since Python 3.3, and in 3.10 it will stop working

(ABC stands for abstract base class.)

This means that ever since Python 3.3 (almost ten years ago!) the correct way to import this is from collections.abc import Mapping, and the old way finally stopped working in Python 3.10.

I'd call it a bug in Google Cloud SDK, but their documentation actually suggests to use Python 3.5 to 3.8, so I suspect they have not tested it on 3.10. Maybe they'll fix it at some point.

Dronir
  • 866
  • 7
  • 10
  • yes, it looks like true. working now. thanks – Khan Dec 02 '21 at 09:41
  • Its same for `MutableMapping`. – Marcin Dec 23 '21 at 10:27
  • this happened to me in gcloud version 368, I updated to latest version in macos following the official guide and python 3.10 and the problem doesn't happen, although, they do say to use python <=3.8. https://cloud.google.com/sdk/docs/install#mac – santiago arizti May 16 '22 at 23:05
  • @khan maybe click the "accept" checkmark on the answer if it helped, if you can. (I don't know if you can, now that the question is closed) – Dronir Aug 17 '22 at 06:36
  • If you don't want to change your python version, you can modify the gsutil code. First, locate the file `which gsutil`, mine is `~/google-cloud-sdk/bin/gsutil`. Then open that file, change this line `CLOUDSDK_PYTHON=$(order_python python3 python2 python2.7 python)` to this `CLOUDSDK_PYTHON=$(order_python python2 python3 python2.7 python)` – Che Huu Feb 24 '23 at 03:08
  • If I understand that correctly, that just changes the priority to use python2 instead of python3, but note that modern MacOS versions do not have a python2 anymore (since version 12.3 Monterey, in 2021), so you would need to install that separately, too. – Dronir Feb 24 '23 at 08:10