安装用于 Python 的 Azure 机器学习 SDKInstall the Azure Machine Learning SDK for Python

本文提供有关该 SDK 的不同安装选项的指导。This article is a guide for different installation options for the SDK.

默认安装Default install

默认安装涵盖大量的用例,不会在环境中安装任何不必要的本机依赖项。The default installation covers a large number of use-cases and will not install any unnecessary native dependencies in your environment. 将通过 azureml-sdk 包安装以下本机包结构,而不会安装任何附加组件:The following native package structure will be installed via the azureml-sdk package without any extra components:

备注

提交运行时,该 SDK 默认会将 azureml-defaults 包安装到执行运行的环境。When submitting runs, the SDK by default installs the azureml-defaults package to the environment where the run is executed. azureml-defaults 包含记录指标、上传项目以及从运行内部访问数据存储等任务所需的 azureml-core 和 applicationinsights 包。azureml-defaults contains the azureml-core and applicationinsights packages required for tasks such as logging metrics, uploading artifacts, and accessing data stores from within the run.

若要安装默认包,请运行以下命令。To install the default packages, run the following command.

pip install --upgrade azureml-sdk

高级安装(安装附加组件)Advanced install (extras)

SDK 包含多个可选组件 (extras),只有在指定时才会安装这些组件。The SDK contains several optional components (extras) that will only be installed if specified. 这些组件包括并非在所有用例中都必需的依赖项,因此,它们未包含在默认安装中,以避免环境过于臃肿。These include dependencies that aren't required for all use-cases, so they are not included in the default installation in order to avoid bloating the environment. 下表概述了可选组件及其用例。The following table outlines optional components and their use-cases.

其他包安装(附加组件)extras  Additional package installs (extras) 用例和安装的包Use-cases and installed packages
accel-models 安装 azureml-accel-modelsInstalls azureml-accel-models. 使用 Azure 机器学习硬件加速模型服务加速 FPGA 上的深度神经网络。Accelerates deep neural networks on FPGAs with the Azure ML Hardware Accelerated Models Service.
automl 安装 azureml-train-automl 和其他必需的依赖项。Installs azureml-train-automl and other required dependencies. 提供用于生成和运行自动化机器学习试验的类。Provides classes for building and running automated machine learning experiments. automl 附加组件还会安装常用的数据科学包,包括 pandasnumpyscikit-learnThe automl extra also installs common data science packages including pandas, numpy, and scikit-learn. 有关使用 automl 的详细信息,请参阅其他用例指南See the additional use-case guidance for more information on working with automl.
contrib 安装 azureml-contrib-* 包,其中包括实验性功能或预览功能。Installs azureml-contrib-* packages, which include experimental functionality or preview features.
databricks 安装非本机包,以确保在 Azure Databricks 环境中操作时能够兼容。Installs non-native packages to ensure compatibility when working within an Azure Databricks environment. 此附加组件不能与其他组件结合使用This extra cannot be combined with other components. 有关在 Azure Databricks 环境中使用该 SDK 的详细信息,请参阅其他用例指南See the additional use-case guidance for more information on using the SDK in an Azure Databricks environment.
datadrift 安装 azureml-datadriftInstalls azureml-datadrift. 包含了用于检测何时模型训练数据已偏离其评分数据的功能。Contains functionality to detect when model training data has drifted from its scoring data.
explain 安装 azureml-explain-model 和其他必需的依赖项。Installs azureml-explain-model and other required dependencies. 包括用于在自动化模型优化中了解详细特征重要性的类。Includes classes for understanding detailed feature importance in automated model tuning.
interpret 安装用于提高模型可解释性的 azureml-interpret,包括黑盒和白盒模型的特征和类别重要性。Installs azureml-interpret used for model interpretability, including feature and class importance for blackbox and whitebox models.
notebooks 安装 azureml-widgets 和其他必需的依赖项。Installs azureml-widgets and other required dependencies. 为 Jupyter 笔记本环境中的交互式小组件提供支持。Provides support for interactive widgets in a Jupyter notebook environment. 如果不是在 Jupyter 笔记本中运行(例如,This is unnecessary to install if you aren't running in a Jupyter notebook (ex. 如果是在 PyCharm 中生成),或者不需要启用小组件,则不必要安装此组件。if you are building in PyCharm), or if you don't need widgets enabled.
services 安装 azureml-contrib-servicesInstalls azureml-contrib-services. 为请求原始 HTTP 访问权限的评分脚本提供功能。Provides functionality for scoring scripts to request raw HTTP access.
tensorboard 安装 azureml-tensorboardInstalls azureml-tensorboard. 提供所需的类和方法来导出试验运行历史记录,以及启动用于可视化试验性能和结构的 TensorBoard。Provides classes and methods for exporting experiment run history and launching TensorBoard for visualizing experiment performance and structure.

与附加组件一起安装Install with extras

若要连同 extras 一起安装 SDK,请在默认安装中追加带方括号的组件名称。To install the SDK with extras, append the component name(s) in brackets onto the default install. 例如,以下命令使用 explainautoml 变体安装 SDK。For example, the following command installs the SDK with the explain and automl variants.

pip install --upgrade azureml-sdk[explain,automl]

试验版Experimental version

若要访问预发布版本(试验版),请在安装过程中使用预发布语义指定版本,例如:To access pre-release version (experimental version), specify the version during installation using pre-release semantics such as:

  • X.YbN # Beta release – Preview channelX.YbN # Beta release – Preview channel
  • X.YrcN # Release Candidate -- PyPiX.YrcN # Release Candidate -- PyPi

若要安装适用于 Python 的 Azure 机器学习 SDK 试验版,请对 pip install 指定 --pre 标志,例如:$ pip install --pre azureml-sdkTo install the experimental version of the Azure Machine Learning SDK for Python, specify the --pre flag to the pip install such as: $ pip install --pre azureml-sdk

自定义安装Custom install

若要运行自定义安装并手动管理环境中的依赖项,可以在 SDK 中单独安装任何包。If you want to run a custom install and manually manage the dependencies in your environment, you can individually install any package in the SDK.

备注

  • 如果有消息指出无法卸载 PyYAML,请改用以下命令:If you get a message that PyYAML can't be uninstalled, use the following command instead:

    pip install --upgrade azureml-sdk[explain,automl] --ignore-installed PyYAML

  • 从 macOS Catalina 开始,zsh (Z shell) 是默认的登录 shell 和交互式 shell。Starting with macOS Catalina, zsh (Z shell) is the default login shell and interactive shell. 在 zsh 中,运行以下命令以使用“\”(反斜杠)来转义方括号:In zsh, use the following command which escapes brackets with "\" (backslash):

    pip install --upgrade azureml-sdk\[explain,automl\]

检查版本Check version

运行以下代码来验证 SDK 版本。Run the following code to verify your SDK version. 若要验证与特定教程和代码示例的兼容性,可能需要执行此检查。This check may be necessary for verifying compatibility with certain tutorials and code samples.

import azureml.core
print(azureml.core.VERSION)

若要详细了解如何为 Azure 机器学习服务配置开发环境,请参阅配置开发环境To learn more about how to configure your development environment for Azure Machine Learning service, see Configure your development environment.

其他用例指南Additional use-case guidance

如果你的用例如下面所述,请记下指导和任何建议的操作。If your use-case is described below, note the guidance and any recommended actions.

用例Use-case 指南Guidance
使用 automl 附加组件 Using the automl extra 在 64 位 Python 环境中安装 SDK。Install the SDK in a 64-bit Python environment. 由于与 LightGBM 框架之间存在依赖关系,因此需要在 64 位环境中安装。A 64-bit environment is required because of a dependency on the LightGBM framework.
使用 Azure DatabricksUsing Azure Databricks 在 Azure Databricks 环境中,请使用此指南中详述的库源来安装 SDK。In the Azure Databricks environment, use the library sources detailed in this guide for installing the SDK. 另请参阅这些提示,进一步了解如何在 Azure Databricks 中使用适用于 Python 的 Azure 机器学习 SDK。Also, see these tips for further information on working with Azure Machine Learning SDK for Python on Azure Databricks.
使用 Azure Data Science Virtual MachineUsing Azure Data Science Virtual Machine 在 2018 年 9 月 27 日之后创建的 Azure Data Science Virtual Machine 已预装 Python SDK。Azure Data Science Virtual Machines created after September 27, 2018 come with the Python SDK preinstalled.
运行 Azure 机器学习教程笔记本   Running Azure Machine Learning tutorials or notebooks 如果所用的 SDK 版本低于教程或笔记本中所述的版本,则应升级你的 SDK。If you are using an older version of the SDK than the one mentioned in the tutorial or notebook, you should upgrade your SDK. 教程和笔记本中的某些功能可能需要其他 Python 包,例如 matplotlibscikit-learnpandasSome functionality in the tutorials and notebooks may require additional Python packages such as matplotlib, scikit-learn, or pandas. 每个教程和笔记本中的说明将会指出所需的包。Instructions in each tutorial and notebook will show you which packages are required.

后续步骤Next steps

尝试通过以下后续步骤来了解如何使用适用于 Python 的 Azure 机器学习服务 SDK:Try these next steps to learn how to use the Azure Machine Learning service SDK for Python:

  1. 阅读概述,通过代码示例了解关键的类和设计模式。Read the overview to learn about key classes and design patterns with code samples.
  2. 遵循此教程开始创建试验和模型。Follow this tutorial to begin creating experiments and models.