首页 > 解决方案 > DevOps 管道在导入 azureml.core 时运行 python 脚本错误

问题描述

我正在尝试在签入时在 DevOps 管道中运行 Python 脚本。一个基本的“hellow world”脚本可以工作,但是当我导入 azureml.core 时,它​​会出现 ModuleNotFoundError:没有名为“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))

标签: pythonazure-devopsazure-machine-learning-service

解决方案


你必须将丢失的包安装到你的 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

推荐阅读