DevOps 管道 运行 python 导入脚本错误 azureml.core

DevOps pipeline running python script error on import azureml.core

我试图在签入时在 DevOps 管道中 运行 一个 Python 脚本。一个基本的 'hellow world' 脚本可以工作,但是当我导入 azureml.core 时,它出错了 ModuleNotFoundError: No module named 'azureml'.

这是有道理的,因为我不知道它将如何找到 azureml.core。我的问题是:如何获取 Python 脚本来查找模块?我是否需要将其作为 DevOps 代码库的一部分签入?或者有什么方法可以通过超链接引用它吗?

这是我的 YML 文件:

trigger:
- master

pool:
  vmImage: ubuntu-latest

steps:
- task: PythonScript@0
  inputs:
    scriptSource: 'filepath'
    scriptPath: test.py

这是我的 python 脚本:

print('hello world')

import azureml.core
from azureml.core import Workspace

# Load the workspace from the saved config file
ws = Workspace.from_config()
print('Ready to use Azure ML {} to work with {}'.format(azureml.core.VERSION, ws.name))

您必须将丢失的包安装到您的 python 中,默认的 python 没有。请使用以下 yml:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: UsePythonVersion@0
  displayName: 'Use Python 3.8'
  inputs:
    versionSpec: 3.8

- script: python3 -m pip install --upgrade pip
  displayName: 'upgrade pip'

- script: python3 -m pip install azureml.core
  displayName: 'Install azureml.core'



- task: PythonScript@0
  inputs: 
    scriptSource: 'filepath'
    scriptPath: test.py