- To learn about the Vertex AI SDK for Python, see Introduction to the Vertex AI SDK for Python.
- To learn how to train a model using the Vertex AI SDK for Python, see the Train a model using Vertex AI and the Python SDK.
- To learn about the classes and methods in the Vertex AI SDK for Python, see the vertex_ai_sdk_for_python_ref_name.
Installation of the Vertex AI SDK for Python includes the following steps:
- Create an isolated Python environment
- Install the Vertex AI SDK package
- Initialize the Vertex AI SDK
Create an isolated Python environment
A Python best practice is to install the Vertex AI SDK in an isolated Python environment for each project. This helps prevent dependency, version, and permissions conflicts. You can create an isolated environment for using the command line in a shell or for using a notebook.
To create an isolated environment when you use the command line, activate a
venv environment. After
venv environment is activated, you're ready to install the
Vertex AI SDK and run your Python scripts. For more information, see
venv to isolate dependencies
and Set up a Python development environment.
To use a notebook for your isolated environment, create a notebook instance. After you create your notebook instance, use it to install the Vertex AI SDK and run your Python scripts. For more information, see Create a user-managed notebooks instance.
Install the Vertex AI SDK package
To install the Vertex AI SDK, run the following command in your virtual environment:
pip install google-cloud-aiplatform
Initialize the Vertex AI SDK
After you install the Vertex AI SDK for Python, you must initialize the SDK with your Vertex AI and Google Cloud details. For example, when you initialize the SDK, you specify information such as your project name, region, and your staging Cloud Storage bucket. The following method is an example of a method that initializes the Vertex AI SDK.
def init_sample( project: Optional[str] = None, location: Optional[str] = None, experiment: Optional[str] = None, staging_bucket: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, ): from google.cloud import aiplatform aiplatform.init( project=project, location=location, experiment=experiment, staging_bucket=staging_bucket, credentials=credentials, encryption_spec_key_name=encryption_spec_key_name, )
- Learn more about the Vertex AI SDK.