Xcode update broke gcloud and gsutil
Asked Answered
L

1

6

A few hours ago I updated Xcode to the latest version, which caused gcloud and gsutil commands to stop working. For example, a minute before the update finished, the command gsutil -m rsync was working fine.

While writing this question, I noticed I no longer have git working.

Since I'm not a Python guy, can someone please explain to me what the hell happened now? I would love some help.

python -V output is Python 2.7.16.

python3 -V output is Python 3.9.0.

pip -V output is pip 20.2.3 from /Users/<MY_USER>/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)

pip3 -V output is pip 20.2.3 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)

This is what I get for gcloud help:

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

And this is what I get for gsutil help:

Traceback (most recent call last):
  File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/gsutil.py", line 13, in <module>
    import bootstrapping
  File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
    import setup  # pylint:disable=g-import-not-at-top
  File "/Users/<MY_USER>/gcloud/sdk/bin/bootstrapping/setup.py", line 57, in <module>
    from googlecloudsdk.core.util import platforms
  File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
    from googlecloudsdk.core.util import importing
  File "/Users/<MY_USER>/gcloud/sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
    import imp
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/imp.py", line 23, in <module>
    from importlib import util
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/util.py", line 2, in <module>
    from . import abc
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/abc.py", line 17, in <module>
    from typing import Protocol, runtime_checkable
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 26, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 124, in <module>
    import enum
  File "/Users/<MY_USER>/gcloud/sdk/lib/third_party/enum/__init__.py", line 26, in <module>
    spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
Lundin answered 7/10, 2020 at 15:0 Comment(0)
L
15

So after almost a day with nothing, I found a solution: what I needed to do was set an environment variable named CLOUDSDK_PYTHON to /usr/bin/python.

I edited my .zprofile and added:

export CLOUDSDK_PYTHON="/usr/bin/python"

I still have no idea what caused it, so I'll be glad for an explanation if anyone cares to take the time.

Lundin answered 7/10, 2020 at 17:2 Comment(2)
gcloud does not seem to support Python 3.9 yet. See this answer: https://mcmap.net/q/216560/-attributeerror-module-39-importlib-39-has-no-attribute-39-util-39 "Python 3.9 is on release candidate and is expected that Gcloud SDK not support 3.9, it is written for be compatible with 2.7.x & 3.6 - 3.8" I had the same problem on Win10 after I updated Python. Seems like gcloud's included Python is not used by default as the newer one was first in the PATH.Sennit
Update 2020-11-04 : Supports Python 3.9 now. I was able to fix the issue using this solution.Felicidadfelicie

© 2022 - 2024 — McMap. All rights reserved.