High severity beginner · Fix: 2-5 min

EnvironmentError

google.auth.exceptions.EnvironmentError

What this error means
The Vertex AI client requires the GOOGLE_CLOUD_PROJECT environment variable to be set with your Google Cloud project ID but it is missing or unset.

Stack trace

traceback
google.auth.exceptions.EnvironmentError: The environment variable GOOGLE_CLOUD_PROJECT is not set. Please set it to your Google Cloud project ID before initializing the Vertex AI client.
QUICK FIX
Set the environment variable GOOGLE_CLOUD_PROJECT to your Google Cloud project ID before initializing the Vertex AI client.

Why it happens

The Vertex AI SDK relies on the GOOGLE_CLOUD_PROJECT environment variable to identify which Google Cloud project to use for API calls. If this variable is not set, the SDK cannot authenticate or route requests properly, causing this error.

Detection

Check for the presence of the GOOGLE_CLOUD_PROJECT environment variable in your runtime environment before initializing the Vertex AI client. Log or assert its presence to catch this early.

Causes & fixes

1

GOOGLE_CLOUD_PROJECT environment variable is not set in the OS environment

✓ Fix

Set the environment variable GOOGLE_CLOUD_PROJECT to your Google Cloud project ID before running your Python application, e.g., export GOOGLE_CLOUD_PROJECT='your-project-id'

2

Running code in an environment (like local machine or container) without Google Cloud SDK configured

✓ Fix

Install and configure the Google Cloud SDK and authenticate with gcloud auth login, then set the project ID environment variable accordingly

3

Using a deployment environment (e.g., Cloud Run, Cloud Functions) without specifying the project ID environment variable

✓ Fix

Configure the deployment environment to include the GOOGLE_CLOUD_PROJECT environment variable with the correct project ID

Code: broken vs fixed

Broken - triggers the error
python
from google.cloud import aiplatform

# This will raise EnvironmentError if GOOGLE_CLOUD_PROJECT is not set
client = aiplatform.gapic.PipelineServiceClient()
# Error occurs here
Fixed - works correctly
python
import os
from google.cloud import aiplatform

# Set environment variable for project ID
os.environ['GOOGLE_CLOUD_PROJECT'] = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')  # Replace with your actual project ID

client = aiplatform.gapic.PipelineServiceClient()
print('Vertex AI client initialized successfully')
Added setting of the GOOGLE_CLOUD_PROJECT environment variable before client initialization to ensure the SDK knows which project to use.

Workaround

Manually pass the project ID as a parameter to Vertex AI client constructors if supported, or wrap client initialization in try/except to catch the EnvironmentError and prompt for setting the environment variable.

Prevention

Always configure your deployment and local environments to include the GOOGLE_CLOUD_PROJECT environment variable or use Google Cloud SDK authentication flows that automatically set this variable.

Python 3.7+ · google-cloud-aiplatform >=1.0.0 · tested on 2.15.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.