本快速入門導覽課程會逐步說明如何安裝Google Cloud Pipeline Components (GCPC) SDK。
安裝最新版本
使用下列指令從 Python Package Index (PyPI) 安裝 Google Cloud SDK:
pip install --upgrade google-cloud-pipeline-components
使用 Google Cloud SDK 匯入預先建構的元件
安裝 Google Cloud SDK 後,即可匯入預先建構的元件。
如需支援元件的 SDK 參考資訊,請參閱 Google Cloud SDK 說明文件。
舉例來說,您可以使用下列程式碼,在管道中匯入及使用 Dataflow 元件。
from google_cloud_pipeline_components.v1.dataflow import DataflowPythonJobOp
from kfp import dsl
@dsl.pipeline(
name=PIPELINE_NAME,
description='Dataflow launch python pipeline'
)
def pipeline(
python_file_path:str = 'gs://ml-pipeline-playground/samples/dataflow/wc/wc.py',
project_id:str = PROJECT_ID,
location:str = LOCATION,
staging_dir:str = PIPELINE_ROOT,
requirements_file_path:str = 'gs://ml-pipeline-playground/samples/dataflow/wc/requirements.txt',
):
dataflow_python_op = DataflowPythonJobOp(
project=project_id,
location=location,
python_module_path=python_file_path,
temp_location = staging_dir,
requirements_file_path = requirements_file_path,
args = ['--output', OUTPUT_FILE],
)