AttributeError: module 'importlib' has no attribute 'util'

Solution 1:

Update from GCP support

GCP support mentioned that the new version 318.0.0 released on 2020.11.10 should support python 3.9

I updated my gcloud sdk to 318.0.0 and now looks like python 3.9.0 is supported.

To fix this issue run

gcloud components update

Fedora 33 includes python 2.7 and to force GCloud SDK to use it please set this environment variable

export CLOUDSDK_PYTHON=python2

You can add this export command to your ~/.bash_profile

Python 3.9 is very new and is expected that Gcloud SDK does not support 3.9, it is written to be compatible with 2.7.x & 3.6 - 3.8 (3.8 can cause some compat issues I recommend to use 3.7)

As a workaround, configure Python 3.8 or 3.7 (these versions work well for Gcloud and most of linux distros) as system wide interpreter and try to use gcloud commands.

Solution 2:

For macOS/Homebrew:

brew install [email protected]
export CLOUDSDK_PYTHON=python3.8
ln -s /usr/local/Cellar/[email protected]/*/bin/python3.8 /usr/local/bin/python3.8

gcloud components update

# the issue is now resolved and you can return to python 3.9
unset CLOUDSDK_PYTHON

Solution 3:

For Mac OS Users

First of all you should run brew update.

If you have this error:

Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core. We don't do this for you automatically to avoid
repeatedly performing an expensive unshallow operation in CI systems (which
should instead be fixed to not use shallow clones). Sorry for the inconvenience!

Run next commands:

git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow

Now,

Update python 3.8 brew upgrade [email protected]

Add python 3.8 to PATH export PATH="/usr/local/opt/[email protected]/bin:$PATH"

Use python 3.8 in Cloud SDK export CLOUDSDK_PYTHON=python3.8

Now, you can update gcloud components gcloud components update

Solution 4:

Happened to me after a brew upgrade. Works with python 3.8.

You need to make python3.8 into your shell path. I executed following lines and it worked

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
alias python=/usr/local/opt/[email protected]/bin/python3

Thank you!

Solution 5:

If you don't want to use Python 2, you can use Python 3.8 on Fedora 33 until the SDK starts supporting Python 3.9.

Install python 3.8 using :

sudo dnf install python3.8

You can verify your installation by running:

python3.8 --version

Then set it as the Google Cloud SDK interpreter:

export CLOUDSDK_PYTHON=python3.8

After this the SDK should work normally.