#development #python #tools

When you use different external tools in the macOS terminal, you'll eventually run into conflicting dependencies. This is the case when you install Python 3.12 and then try to use gcloud.

This morning, I was greeted with the following error message:

 1Traceback (most recent call last):
 2  File "/Users/<username>/google-cloud-sdk-1/lib/gcloud.py", line 137, in <module>
 3    main()
 4  File "/Users/<username>/google-cloud-sdk-1/lib/gcloud.py", line 90, in main
 5    from googlecloudsdk.core.util import encoding
 6  File "/Users/wujames/test-python/google-cloud-sdk-1/lib/googlecloudsdk/__init__.py", line 23, in <module>
 7    from googlecloudsdk.core.util import importing
 8  File "/Users/<username>/google-cloud-sdk-1/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
 9    import imp
10ModuleNotFoundError: No module named 'imp'

After some research, I found that the issue was related to the Python version. I recently installed Python 3.12 and that was causing the issue. The solution was to update the gcloud SDK to use the latest Python version.

That however wasn't so easy as the gcloud tool itself didn't want to start anymore. Thanks to StackOverflow, I was able to find a solution. Here's what I did:

1CLOUDSDK_PYTHON=/opt/homebrew/bin/python3.11 gcloud components update

This command tells the gcloud SDK to use the Python 3.11 version. After running this command, the gcloud tool started to update itself to a version that does support Python 3.12.

After the update, I was able to use the gcloud tool again without any issues. I hope this helps you if you run into the same issue.