google-app-enginegoogle-cloud-platformgoogle-cloud-sdk

Google Cloud devappserver


Since the new update of 427.0.0 when I run the command: python2 /usr/lib/google-cloud-sdk/bin/dev_appserver.py --max_module_instances="default:1" --dev_appserver_log_level=info --enable_host_checking=false --automatic_restart=no --runtime_python_path="$(pwd)/lenv/bin/python3.11" --port=8080 --support_datastore_emulator=yes --default_gcs_bucket_name=x --datastore_emulator_port=8081 "$(pwd)" In order to test locally using dev_appserver.py with legacy bundled services in python3. I get the error:

ERROR: Python 2 is not compatible with the Google Cloud SDK. Please use Python version 3.5 and up.

If you have a compatible Python interpreter installed, you can use it by setting the CLOUDSDK_PYTHON environment variable to point to it.

Reverting the version to the previous one did not work. If I set the CLOUDSDK_PYTHON env variable by using export CLOUDSDK_PYTHON=/usr/bin/python3 the same error still stands (I did source the bashrc afterwards and it exists in env).


Solution

  • 427.0.0 has the following under 'Breaking Changes'

    (Google Cloud CLI) Deprecated Python 2. The minimum supported Python version is Python 3.5.

    This means you now have to run it with Python 3. The documentation says

    Regardless of your app's runtime or language version, you must run dev_appserver.py with Python 3 and set the CLOUDSDK_DEVAPPSERVER_PYTHON environment variable in your shell to the path of your Python 2 interpreter.

    This means you now run it with

    python3 CLOUD_SDK_ROOT/bin/dev_appserver.py app.yaml

    If you're running versions 426.0.0 or lower, then you have to use

    python CLOUD_SDK_ROOT/bin/dev_appserver.py --runtime_python_path=/usr/bin/python3 app.yaml

    or

    python CLOUD_SDK_ROOT/bin/dev_appserver.py --runtime_python_path="python27=/usr/bin/python2.7,python3=/usr/bin/python3" app.yaml]

    where python refers to your python 2 installation