Create a notebook Stay organized with collections Save and categorize content based on your preferences.
This section shows you how to create a Jupyter notebook in aVertex AI Workbench instance.Vertex AI Workbench instances are Jupyter notebook-based developmentenvironments for the entire data science workflow.Vertex AI Workbench instances are prepackaged with JupyterLaband have a preinstalled suite of deep learning packages, including supportfor the TensorFlow and PyTorch frameworks.For more information, seeIntroduction toVertex AI Workbench instances.
After you create a notebook in Vertex AI Workbench, you runsequential portions of Python code to do most of the work to generate yourpredictions.
Before you begin
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI and Notebooks APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- Create a project: To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission.Learn how to grant roles.
Verify that billing is enabled for your Google Cloud project.
Enable the Vertex AI and Notebooks APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission.Learn how to grant roles.
Create a Vertex AI Workbench instance
To create a Vertex AI Workbench instance, do the following:
In the Google Cloud console, open your Google Cloud project if it's notalready open.
In the Google Cloud console, go to theVertex AI WorkbenchInstances page.
If the option to enable theNotebooks API appears, clickEnable. Itmight take a few moments for the enabling process to complete.
Click Create new.
In theNew instance dialog, forName, enter a name for yourinstance.
ForRegion, selectus-central1 (Iowa).
ForZone, selectus-central1-a.
ClickCreate. If you want to learn more about your instance, after itappears in your list of instances click its name to see its properties.
Prepare your notebook
Your Vertex AI Workbench instance is already authenticated touse your Google Cloud project. However, you must install and initializethe Vertex AI SDK for Python. This section walks you through these steps.
After you create your notebook, you use it to enter and run the sequentialsnippets of code in this tutorial. Each snippet of code must be run individuallyand in order.
Create and open your notebook
Your notebook is where you run the code in this tutorial. It's a file with theextension.ipynb. When you create it, it's untitled. You canrename it after it's open. To create and open your notebook, do the following:
In the Google Cloud console, go to theInstances page.
Next to your instance's name, clickOpen JupyterLab.
Your Vertex AI Workbench instance opens the JupyterLab environment.
In JupyterLab, selectFile > New > Notebook.
Your new notebook file opens and theSelect kernel dialog appears.
In theSelect kernel dialog, select thePython 3 kernel.
In the left-navigation pane of JupyterLab, find your new notebook,namedUntitled.ipynb. To rename it, right-clickthe notebook name, clickRename, and enter a new name.
Install the Vertex AI SDK for Python
After you open your notebook, you must install the Vertex AI SDK for Python.You use the Vertex AI SDK for Python to make Vertex AI API calls thatcreate your dataset, create your model, train and deploy your model, andmake predictions with your model. For more information, seeUse theVertex AI SDK for Python.
When you install Vertex AI SDK for Python, other Google Cloud SDKs on whichit's dependent are also installed. Two of those SDKs are used in this tutorial:
Cloud Storage - When you use the Vertex AI SDK for Python to makeVertex AI API calls, Vertex AI stores artifacts in aCloud Storage bucket. The bucket is referred to as astaging bucket. Youspecify the staging bucket when youinitialize theVertex AI SDK for Python. For more information,seePython client for Google Cloud storageAPI.
BigQuery - Vertex AI trains your model using aBigQuery public dataset. The BigQuery SDK must be installedto access and download the dataset used in this tutorial. For moreinformation, seeBigQuery API clientlibraries.
To install the Vertex AI SDK for Python and its dependent SDKs, run the followingcode.
# Install the Vertex AI SDK! pip3 install --upgrade --quiet google-cloud-aiplatformThe--quiet flag suppresses output so that only errors display, if thereare any. The exclamation mark (!) indicates that this is a shell command.
Because this is the first code you're running in your new notebook, youenter it into the blank code cell at the top of your notebook. After you entercode in a code cell, click

As you proceed through this tutorial, run code in the empty code cell thatautomatically appears below the most recently run code. If you want to manuallyadd a new code cell, click the notebook file's

Set your project ID and region
In this step, you set your project ID and your region. You first assign them tovariables so they can be easily referenced later in this tutorial. Next, you usethegcloud config command to set them for your Google Cloud session.Later, you use them and your Cloud Storage bucket URI to initialize theVertex AI SDK for Python.
Set your project ID
To set your project ID, do the following:
Locate your Google Cloud project ID. For more information, seeFind your project ID.
Run the following in a code cell in your notebook. In the code, replacePROJECT_ID with the project ID you just located. The outputthis command generates is
Updated property [core/project].project_id="PROJECT_ID"#@param{type:"string"}#Settheprojectid!gcloudconfigsetproject${project_id}
Set your region
This tutorial uses theus-central1 region. To set your region, do thefollowing:
Run the following code to set the
regionvariable that's used byVertex AI tous-central1. This command doesn't generate output. Formore information, seeChoose yourlocation.region="us-central1"#@param{type:"string"}
Create a Cloud Storage bucket
This tutorial requires a Cloud Storage bucket that's used by Vertex AIto stage artifacts. Vertex AI stores the data associated with the datasetyou create and model resources in the staging bucket. This data is retained andavailable across sessions. In this tutorial, Vertex AI also stores yourdataset in the staging bucket. You specify your staging bucket when youinitialize the Vertex AI SDK for Python.
Every Cloud Storage bucket name must be globally unique. If you choose a namethat's been used, the command to create your bucket fails. Thefollowing code uses a datetime stamp and your project name to create a uniquebucket name. You append the bucket name togs:// to create the URI for yourCloud Storage bucket. Theecho shell command shows you the URI so you canverify it created correctly.
To set your bucket's name and URI, run the following code. The last linedisplays the URI of your Cloud Storage bucket.
bucket_name="bucket-name-placeholder"# @param {type:"string"}bucket_uri=f"gs://{bucket_name}"fromdatetimeimportdatetimetimestamp=datetime.now().strftime("%Y%m%d%H%M%S")ifbucket_name==""orbucket_nameisNoneorbucket_name=="bucket-name-placeholder":bucket_name=project_id+"aip-"+timestampbucket_uri="gs://"+bucket_name!echo$bucket_uriTo create a bucket using the Cloud Storage client library and the bucketURI, run the following code. This code doesn't generate output.
fromgoogle.cloudimportstorageclient=storage.Client(project=project_id)# Create a bucketbucket=client.create_bucket(bucket_name,location=region)To verify your bucket created successfully, run the following:
print("Bucket {} created.".format(bucket.name))
Initialize the Vertex AI SDK for Python
To initialize the Vertex AI SDK for Python, you first import its library,aiplatform. Next, you callaiplatform.init and pass in values for thefollowing parameters:
project- Theprojectspecifies which Google Cloud project to use whenyou use the Vertex AI SDK for Python to make calls to the Vertex AI API.In this tutorial you specify your Google Cloud project with its name. Youcan also specify your project with its project number.location- Thelocationspecifies which Google Cloud region to use whenyou make API calls. If you don't specify a location, the Vertex AI SDK for Pythonusesus-central1.staging_bucket- Thestaging_bucketspecifies which Cloud Storagebucket is used to stage artifacts when you use the Vertex AI SDK for Python. Youspecify the bucket with a URI that starts withgs://. In this tutorial, youuse the URI created earlier inCreate a Cloud Storage bucket.
To set your Google Cloud project, region, and staging bucket, run thefollowing command. This command doesn't generate output.
fromgoogle.cloudimportaiplatform# Initialize the Vertex AI SDKaiplatform.init(project=project_id,location=region,staging_bucket=bucket_uri)Initialize BigQuery
This tutorial uses a BigQuery public dataset of penguins to train amodel. After Vertex AI trains the model, you specify parameters thatrepresent characteristics of penguins, and the model uses those characteristicsto predict the species of penguin they represent. For more information aboutpublic datasets, seeBigQuery public datasets.
Before you use the BigQuery dataset, you must initializeBigQuery with your project ID. To do this, run the following command.This command doesn't generate output.
fromgoogle.cloudimportbigquery# Set up BigQuery clientbq_client=bigquery.Client(project=project_id)Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-11-24 UTC.