安裝 Vertex AI SDK for Python 時,系統也會安裝 Vertex AI Python 用戶端程式庫。Vertex AI SDK 和 Vertex AI Python 用戶端程式庫提供類似功能,但精細程度不同。Vertex AI SDK 的抽象層級高於用戶端程式庫,適用於大多數常見的資料科學工作流程。如需較低層級的功能,請使用 Vertex AI Python 用戶端程式庫。
Vertex AI SDK 適用於 Python,而 Vertex AI 用戶端程式庫則適用於 Python、Java 和 Node.js。如要瞭解如何安裝 Java 或 Node.js 用戶端程式庫,請參閱「安裝 Vertex AI 用戶端程式庫」。如果沒有您偏好程式設計語言的用戶端程式庫,可以使用 Vertex AI REST API。詳情請參閱 Vertex AI REST 參考資料。
同時使用 Vertex AI Python 用戶端程式庫和 SDK
如果您使用 Vertex AI SDK for Python,但發現需要更大的彈性或控制權,或是需要 Vertex AI SDK 未提供的方法,可以在相同的工作流程中使用 Vertex AI Python 用戶端程式庫。Vertex AI Python 用戶端程式庫使用不同的命名空間存取 Vertex AI API。您可以在同一個 Python 指令碼中使用用戶端程式庫和 Vertex AI SDK for Python 命名空間,只要在 Python 指令碼中為每個命名空間新增 import 行即可。
[[["容易理解","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-04 (世界標準時間)。"],[],[],null,["# Introduction to the Vertex AI SDK for Python\n\nThe Vertex AI SDK for Python helps you automate data ingestion, train models, and\nget predictions on Vertex AI. The Vertex AI SDK uses Python code to\naccess the Vertex AI API so that you can programmatically accomplish most of what\nyou can do in the Google Cloud console.\n\nTo learn how to install or update the Vertex AI SDK for Python, see [Install the\nVertex AI SDK for Python](/vertex-ai/docs/start/install-sdk). For more information, see\nthe [Vertex AI SDK for Python API reference documentation](/python/docs/reference/aiplatform/latest).\n\nWhy use the Vertex AI SDK\n-------------------------\n\nThe Vertex AI SDK for Python is recommended if you're an experienced machine\nlearning (ML) and artificial intelligence (AI) engineer or a data scientist who\nwants to programmatically automate your workflow. The Vertex AI SDK for Python is\nsimilar to the Vertex AI Python client library, except the\nVertex AI SDK is higher-level and less granular. For more information, see\n[Understand the SDK and client library differences](#sdk-vs-client-library).\n\n\u003cbr /\u003e\n\nWrite code with the Vertex AI SDK for Python\n--------------------------------------------\n\nTo use the Vertex AI SDK for Python:\n\n1. Install the `google-cloud-aiplatform` package, which includes both the Vertex AI SDK for Python and the Vertex AI Python client library, by running the following command in your virtual environment:\n\n pip install --upgrade google-cloud-aiplatform\n\n2. Use the following code to import the `google.cloud.aiplatform` namespace:\n\n from google.cloud import aiplatform\n\n | **Preview:** To use features for the Vertex AI SDK for Python that are still in [preview](/products#product-launch-stages), import `vertexai.preview`: \n |\n | ```python\n | import vertexai.preview\n | ```\n\n \u003cbr /\u003e\n\n3.\n\n If you're using a local shell, then create local authentication credentials for your user\n account:\n\n ```bash\n gcloud auth application-default login\n ```\n\n You don't need to do this if you're using Cloud Shell.\n\n\n If an authentication error is returned, and you are using an external identity provider\n (IdP), confirm that you have\n [signed in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n### Learn about the Vertex AI SDK for Python\n\nSee the following documentation:\n\n- [Vertex AI SDK class overview](/vertex-ai/docs/python-sdk/python-sdk-class-overview): introduces the key classes and functionality in the Vertex AI SDK.\n\n- [Python reference for Vertex AI](/python/docs/reference/aiplatform/latest): contains reference documentation for all of the namespaces, classes, methods, and properties in the `google-cloud-aiplatform` package, which includes the Vertex AI SDK, the Vertex AI SDK preview, and the Vertex AI Client libraries.\n\n### Try code samples and tutorials\n\nNotebook tutorials show how to use the Vertex AI SDK for Python as part of a\nlarger workflow. For more information, see\n[Vertex AI notebook tutorials](/vertex-ai/docs/tutorials/jupyter-notebooks).\n\nCode samples in the Vertex AI SDK for Python GitHub repository show you how to\ncomplete individual tasks. For more information, see the\n[Vertex AI SDK for Python GitHub repository](https://github.com/googleapis/python-aiplatform/). \n| To see an example of using the Vertex AI SDK as part of a more comprehensive workflow,\n| run the \"Custom training and online prediction\" notebook in one of the following\n| environments:\n|\n| [Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fcustom%2Fsdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [Open\n| in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fcustom%2Fsdk-custom-image-classification-online.ipynb)\n|\n|\n| \\|\n|\n| [View on GitHub](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/custom/sdk-custom-image-classification-online.ipynb)\n\nUnderstand the Vertex AI SDK and client library differences\n-----------------------------------------------------------\n\nWhen you install the Vertex AI SDK for Python, the Vertex AI Python client\nlibrary is also installed. The Vertex AI SDK and the\nVertex AI Python client library provide similar functionality with\ndifferent levels of granularity. The Vertex AI SDK operates at a\nhigher level of abstraction than the client library and is suitable for most\ncommon data science workflows. If you need lower-level functionality, then use\nthe Vertex AI Python client library.\n\nThe Vertex AI SDK is available for Python and a Vertex AI client\nlibrary is available for Python, Java, and Node.js. To learn how to install the\nJava or Node.js client library, see\n[Install the Vertex AI client libraries](/vertex-ai/docs/start/client-libraries).\nIf a client library isn't available in your preferred programming language, you\ncan use the Vertex AI REST API. For more information, see the\n[Vertex AI REST reference](/vertex-ai/docs/reference/rest).\n\n### Use Vertex AI Python client library and SDK together\n\nIf you use the Vertex AI SDK for Python and discover you need greater flexibility\nor control, or if you need a method not included in the Vertex AI SDK, you\ncan use the Vertex AI Python client library in the same workflow. The\nVertex AI Python client library uses a different namespace to access the\nVertex AI API. The client library and the Vertex AI SDK for Python\nnamespaces can be used in the same Python script by adding an `import` line for\neach in your Python script.\n\n### Import the Vertex AI Python client library namespace\n\nThe Vertex AI Python client library namespace is\n`google.cloud.aiplatform.gapic`. This namespace maps to the\n`google.cloud.aiplatform_v1` namespace. These two namespaces can be used\ninterchangeably. To import the Python client library, include one of the\nfollowing in your Python script: \n\n```\nfrom google.cloud import aiplatform_v1\n``` \n\n```\nfrom google.cloud.aiplatform import gapic\n```\n\nWhat's next\n-----------\n\n- Learn how to [choose a training method](/vertex-ai/docs/start/training-methods)."]]