解决Google Cloud Platform构建Cloud Run应用及安装Gcloud SDK时出现的collections.Mapping AttributeError问题
What's Causing This?
This error happens because the Google Cloud SDK code tries to access collections.Mapping—an attribute that was deprecated in Python 3.3 and fully removed in Python 3.10. For your setup (Python 3.8.12), there are two main reasons this might occur:
- Wrong Python Version Being Used: Even if you have Python 3.8 installed, the SDK might be defaulting to a newer Python version (3.10+) from your system.
- Incompatible SDK Version: Recent Google Cloud SDK releases have dropped support for Python 3.8, so the version you downloaded isn’t built to work with your Python setup.
Step-by-Step Solutions
1. Force the SDK to Use Your Python 3.8 Installation
First, find the path to your Python 3.8 executable:
which python3.8
This will output something like /usr/local/bin/python3.8 or the path to your virtual environment’s Python 3.8.
Next, set the CLOUDSDK_PYTHON environment variable to this path before running the install script:
# For bash/zsh export CLOUDSDK_PYTHON=/path/to/your/python3.8 # Re-run the SDK install script ./google-cloud-sdk/install.sh
This tells the SDK explicitly to use your Python 3.8 version instead of the system default.
2. Install an Older SDK Version Compatible with Python 3.8
If the latest SDK no longer supports Python 3.8, download an archived release that does (look for versions released before mid-2023, when Python 3.8 support was phased out). Once downloaded, follow the installation steps again, making sure to set the CLOUDSDK_PYTHON variable as outlined above.
3. Upgrade Python to 3.9+ (Recommended)
Python 3.8 reached end-of-life in October 2024, so upgrading to a supported version (3.9 or higher) fixes this SDK issue and ensures you get security updates. After upgrading, verify your default Python version:
python3 --version
Then re-run the Google Cloud SDK install script—it should work without the collections.Mapping error.
Additional Checks
- If using a virtual environment, activate it before running the install script to ensure the correct Python version is active.
- Confirm the environment variable is set correctly with
echo $CLOUDSDK_PYTHONto make sure it points to your Python 3.8 executable.
Content of the question is sourced from Stack Exchange, asked by Eshan Chatty

