分離環境でノートブックを使用するには、Vertex AI Workbench インスタンスを作成します。次に、Vertex AI SDK をインストールし、Vertex AI Workbench インスタンスのノートブックから Python スクリプトを実行します。詳細については、Vertex AI Workbench インスタンスを作成するをご覧ください。
Vertex AI SDK パッケージをインストールまたは更新する
Vertex AI SDK をインストールまたは更新するには、仮想環境で次のコマンドを実行します。
pip install --upgrade google-cloud-aiplatform
Vertex AI SDK を初期化する
Vertex AI SDK for Python をインストールしたら、Vertex AI と Google Cloud の詳細を使用して SDK を初期化する必要があります。たとえば、SDK を初期化するときに、プロジェクト名、リージョン、ステージング済み Cloud Storage バケットなどの情報を指定します。Vertex AI SDK を初期化するメソッドの例を次に示しす。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-02 UTC。"],[],[],null,["# Install the Vertex AI SDK for Python\n\nUse the Vertex AI SDK for Python to automate your machine learning (ML) workflows.\nThis topic shows you how to install the Vertex AI SDK for Python. For more\ninformation about the Vertex AI SDK, see the following resources:\n\n- To learn about the Vertex AI SDK for Python, see [Introduction to the Vertex AI SDK for Python](/vertex-ai/docs/python-sdk/use-vertex-ai-python-sdk).\n- To learn how to train a model using the Vertex AI SDK for Python, see the [Train\n a model using Vertex AI and the Python\n SDK](/vertex-ai/docs/tutorials/tabular-bq-prediction).\n- To learn about the classes and methods in the Vertex AI SDK for Python, see the [Vertex AI SDK reference](/python/docs/reference/aiplatform/latest/google.cloud.aiplatform).\n\nInstallation of the Vertex AI SDK for Python includes the following steps:\n\n1. [Create an isolated Python environment](#create-isolated-environment)\n2. [Install the Vertex AI SDK package](#install-python-sdk)\n3. [Initialize the Vertex AI SDK](#initialize-python-sdk)\n\nCreate an isolated Python environment\n-------------------------------------\n\nA Python best practice is to install the Vertex AI SDK in an\nisolated Python environment for each project. This helps prevent dependency,\nversion, and permissions conflicts. You can create an isolated environment for\nusing the command line in a shell or for using a notebook.\n\nTo create an isolated environment when you use the command line, [activate a\n`venv` environment](/python/docs/setup#installing_and_using_virtualenv). After\nthe `venv` environment is activated, you're ready to install the\nVertex AI SDK and run your Python scripts. For more information, see\n[Use `venv` to isolate dependencies](/python/docs/setup#installing_and_using_virtualenv)\nand [Set up a Python development environment](/python/docs/setup).\n\nTo use a notebook in an isolated environment, you can create a\nVertex AI Workbench instance. Then, install the Vertex AI SDK\nand run your Python scripts from a notebook on your Vertex AI Workbench instance.\nFor more information, see\n[Create a Vertex AI Workbench instance](/vertex-ai/docs/workbench/instances/create).\n\nInstall or update the Vertex AI SDK package\n-------------------------------------------\n\nTo install or update the Vertex AI SDK, run the following command in your\nvirtual environment: \n\n```\npip install --upgrade google-cloud-aiplatform\n```\n\nInitialize the Vertex AI SDK\n----------------------------\n\nAfter you install the Vertex AI SDK for Python, you must initialize the SDK with\nyour Vertex AI and Google Cloud details. For example, when you\ninitialize the SDK, you specify information such as your project name, region,\nand your staging Cloud Storage bucket. The following method is an example of\na method that initializes the Vertex AI SDK. \n\n def init_sample(\n project: Optional[str] = None,\n location: Optional[str] = None,\n experiment: Optional[str] = None,\n staging_bucket: Optional[str] = None,\n credentials: Optional[google.auth.credentials.Credentials] = None,\n encryption_spec_key_name: Optional[str] = None,\n service_account: Optional[str] = None,\n ):\n\n import https://cloud.google.com/python/docs/reference/vertexai/latest/\n\n https://cloud.google.com/python/docs/reference/vertexai/latest/.init(\n project=project,\n location=location,\n experiment=experiment,\n staging_bucket=staging_bucket,\n credentials=credentials,\n encryption_spec_key_name=encryption_spec_key_name,\n service_account=service_account,\n )\n\nWhat's next\n-----------\n\n- Learn more about the [Vertex AI SDK](/vertex-ai/docs/python-sdk/use-vertex-ai-python-sdk)."]]