在 Azure 机器学习中创建和使用软件环境Create & use software environments in Azure Machine Learning

适用于:是基本版是企业版               (升级到企业版APPLIES TO: yesBasic edition yesEnterprise edition                    (Upgrade to Enterprise edition)

本文介绍如何创建和管理 Azure 机器学习环境In this article, learn how to create and manage Azure Machine Learning environments. 使用环境可以在项目软件依赖项演化时对其进行跟踪和再现。Use the environments to track and reproduce your projects' software dependencies as they evolve.

软件依赖项管理是开发人员的常见任务。Software dependency management is a common task for developers. 你希望在无需进行大量手动软件配置的情况下,确保版本可以再现。You want to ensure that builds are reproducible without extensive manual software configuration. Azure 机器学习 Environment 类会考虑本地开发解决方案(例如 pip 和 Conda),并通过 Docker 功能进行分布式云开发。The Azure Machine Learning Environment class accounts for local development solutions such as pip and Conda and distributed cloud development through Docker capabilities.

本文中的示例演示如何执行以下操作:The examples in this article show how to:

  • 创建环境并指定包依赖项。Create an environment and specify package dependencies.
  • 检索和更新环境。Retrieve and update environments.
  • 使用环境进行训练。Use an environment for training.
  • 使用环境进行 Web 服务部署。Use an environment for web service deployment.

有关环境在 Azure 机器学习中的作用的综合概述,请参阅什么是 ML 环境?For a high-level overview of how environments work in Azure Machine Learning, see What are ML environments? 若要了解如何配置开发环境,请参阅此文For information about configuring development environments, see here.

先决条件Prerequisites

创建环境Create an environment

以下部分探讨为试验创建环境的多种方式。The following sections explore the multiple ways that you can create an environment for your experiments.

实例化环境对象Instantiate an environment object

若要手动创建环境,请从 SDK 导入 Environment 类。To manually create an environment, import the Environment class from the SDK. 然后使用以下代码实例化某个环境对象。Then use the following code to instantiate an environment object.

from azureml.core.environment import Environment
Environment(name="myenv")

使用特选环境Use a curated environment

特选环境包含 Python 包的集合,默认情况下可以在你的工作区中使用。Curated environments contain collections of Python packages and are available in your workspace by default. 这些环境由缓存的 Docker 映像支持,降低了运行准备成本。These environments are backed by cached Docker images which reduces the run preparation cost. 可以先从这些常用的特选环境中选择一个:You can select one of these popular curated environments to start with:

  • AzureML-Minimal 环境包含最小的一组包,用于启用运行跟踪和资产上传。The AzureML-Minimal environment contains a minimal set of packages to enable run tracking and asset uploading. 在创建自己的环境时,可以将其作为起点。You can use it as a starting point for your own environment.

  • AzureML-Tutorial 环境包含常用的数据科学包。The AzureML-Tutorial environment contains common data science packages. 这些包包括 Scikit-learn、Pandas 和 Matplotlib,以及更大的 azureml-sdk 包集。These packages include Scikit-Learn, Pandas, Matplotlib, and a larger set of azureml-sdk packages.

如需特选环境的列表,请参阅特选环境一文。For a list of curated environments, see the curated environments article.

使用 Environment.get 方法选择一个特选环境:Use the Environment.get method to select one of the curated environments:

from azureml.core import Workspace, Environment

ws = Workspace.from_config()
env = Environment.get(workspace=ws, name="AzureML-Minimal")

可以使用以下代码列出特选环境及其包:You can list the curated environments and their packages by using the following code:

envs = Environment.list(workspace=ws)

for env in envs:
    if env.startswith("AzureML"):
        print("Name",env)
        print("packages", envs[env].python.conda_dependencies.serialize_to_string())

警告

请不要在自己的环境名称的开头使用 AzureML 前缀。Don't start your own environment name with the AzureML prefix. 此前缀专用于特选环境。This prefix is reserved for curated environments.

使用 Conda 依赖项或 pip 要求文件Use Conda dependencies or pip requirements files

可以通过 Conda 规范或 pip 要求文件创建环境。You can create an environment from a Conda specification or a pip requirements file. 使用 from_conda_specification() 方法或 from_pip_requirements() 方法。Use the from_conda_specification() method or the from_pip_requirements() method. 在方法参数中包含所需文件的环境名称和文件路径。In the method argument, include your environment name and the file path of the file that you want.

# From a Conda specification file
myenv = Environment.from_conda_specification(name = "myenv",
                                             file_path = "path-to-conda-specification-file")

#From a pip requirements file
myenv = Environment.from_pip_requirements(name = "myenv"
                                          file_path = "path-to-pip-requirements-file")

启用 DockerEnable Docker

当你启用 Docker 时,Azure 机器学习会生成一个 Docker 映像,并根据你的规范在该容器中创建一个 Python 环境。When you enable Docker, Azure Machine Learning builds a Docker image and creates a Python environment within that container, given your specifications. Docker 映像会被缓存并重复使用:在新环境中首次运行的时间通常比构建映像的时间更长。The Docker images are cached and reused: the first run in a new environment typically takes longer as the image is build.

使用 Azure 机器学习 Environment 类的 DockerSection,可以精细地自定义和控制运行训练的来宾操作系统。The DockerSection of the Azure Machine Learning Environment class allows you to finely customize and control the guest operating system on which you run your training. 可以使用 arguments 变量来指定要传递到 Docker run 命令的额外参数。The arguments variable can be used to specify extra arguments to pass to the Docker run command.

# Creates the environment inside a Docker container.
myenv.docker.enabled = True

默认情况下,新生成的 Docker 映像显示在与工作区关联的容器注册表中。By default, the newly built Docker image appears in the container registry that's associated with the workspace. 存储库名称的格式为“azureml/azureml_<uuid>”。The repository name has the form azureml/azureml_<uuid>. 该名称的唯一标识符 (uuid) 部分对应于基于环境配置计算出的哈希。The unique identifier (uuid) part of the name corresponds to a hash that's computed from the environment configuration. 这种对应使得服务能够确定给定的环境是否已存在可重复使用的映像。This correspondence allows the service to determine whether an image for the given environment already exists for reuse.

使用预生成的 Docker 映像Use a prebuilt Docker image

服务会自动使用基于 Ubuntu Linux 的基础映像之一。The service automatically uses one of the Ubuntu Linux-based base images. 它会安装指定的 Python 包。It installs the specified Python packages. 基础映像具有 CPU 版本和 GPU 版本。The base image has CPU versions and GPU versions. Azure 机器学习会自动检测要使用的版本。Azure Machine Learning automatically detects which version to use. 还可以使用自定义 Docker 基础映像It is also possible to use a custom Docker base image.

# Specify custom Docker base image and registry, if you don't want to use the defaults
myenv.docker.base_image="your_base-image"
myenv.docker.base_image_registry="your_registry_location"

重要

Azure 机器学习仅支持提供以下软件的 Docker 映像:Azure Machine Learning only supports Docker images that provide the following software:

  • Ubuntu 16.04 或更高版本。Ubuntu 16.04 or greater.
  • Conda 4.5.# 或更高版本。Conda 4.5.# or greater.
  • Python 3.5.#、3.6.# 或 3.7.#。Python 3.5.#, 3.6.# or 3.7.#.

使用你自己的 DockerfileUse your own Dockerfile

还可以指定自定义 Dockerfile。You can also specify a custom Dockerfile. 最简单的方法是使用 Docker FROM 命令从某个 Azure 机器学习基础映像开始,然后添加自己的自定义步骤。It's simplest to start from one of Azure Machine Learning base images using Docker FROM command, and then add your own custom steps. 如果需要安装非 Python 包作为依赖项,请使用此方法。Use this approach if you need to install non-Python packages as dependencies. 记住将基础映像设置为“None”。Remember to set the base image to None.

# Specify docker steps as a string. 
dockerfile = r"""
FROM mcr.microsoft.com/azureml/base:intelmpi2018.3-ubuntu16.04
RUN echo "Hello from custom container!"
"""

# Set base image to None, because the image is defined by dockerfile.
myenv.docker.base_image = None
myenv.docker.base_dockerfile = dockerfile

# Alternatively, load the string from a file.
myenv.docker.base_image = None
myenv.docker.base_dockerfile = "./Dockerfile"

指定你自己的 Python 解释器Specify your own Python interpreter

在某些情况下,自定义基础映像可能已包含带有你要使用的包的 Python 环境。In some situations, your custom base image may already contain a Python environment with packages that you want to use.

若要使用你自己的已安装包并禁用 Conda,请设置参数 Environment.python.user_managed_dependencies = TrueTo use your own installed packages and disable Conda, set the parameter Environment.python.user_managed_dependencies = True. 请确保基础映像包含 Python 解释器,并包含你的训练脚本所需的包。Ensure that the base image contains a Python interpreter, and has the packages your training script needs.

例如,若要在安装了 NumPy 包的基本 Miniconda 环境中运行,请首先指定 Dockerfile,其中包含安装包的步骤。For example, to run in a base Miniconda environment that has NumPy package installed, first specify a Dockerfile with a step to install the package. 然后将用户管理的依赖项设置为 TrueThen set the user-managed dependencies to True.

还可以通过设置 Environment.python.interpreter_path 变量来指定特定 Python 解释器在映像中的路径。You can also specify a path to a specific Python interpreter within the image, by setting the Environment.python.interpreter_path variable.

dockerfile = """
FROM mcr.microsoft.com/azureml/base:intelmpi2018.3-ubuntu16.04
RUN conda install numpy
"""

myenv.docker.base_image = None
myenv.docker.base_dockerfile = dockerfile
myenv.python.user_managed_dependencies=True
myenv.python.interpreter_path = "/opt/miniconda/bin/python"

警告

如果在 Docker 映像中安装了某些 Python 依赖项,但忘记设置 user_managed_dependencies = True,则执行环境中不会存在这些包,因此会导致运行时失败。If you install some Python dependencies in your Docker image and forget to set user_managed_dependencies = True, those packages will not exist in the execution environment thus causing runtime failures. 默认情况下,Azure ML 会使用你指定的依赖项构建一个 Conda 环境,并会在该环境中执行运行,而不是使用你在基础映像上安装的任何 Python 库。By default, Azure ML will build a Conda environment with dependencies you specified, and will execute the run in that environment instead of using any Python libraries that you installed on the base image.

检索映像详细信息Retrieve image details

对于已注册的环境,可以使用以下代码检索映像详细信息,其中 detailsDockerImageDetails 的实例 (AzureML Python SDK >= 1.11),并提供有关环境映像的所有信息,例如 dockerfile、注册表和映像名称。For a registered environment, you can retrieve image details using the following code where details is an instance of DockerImageDetails (AzureML Python SDK >= 1.11) and provides all the information about the environment image such as the dockerfile, registry, and image name.

details = environment.get_image_details(workspace=ws)

使用现有环境Use existing environments

如果本地计算机上存在现有的 Conda 环境,则可以使用服务创建环境对象。If you have an existing Conda environment on your local computer, then you can use the service to create an environment object. 采用这种策略可以在远程运行中重复使用本地交互式环境。By using this strategy, you can reuse your local interactive environment on remote runs.

以下代码从现有的 Conda 环境 mycondaenv 创建环境对象。The following code creates an environment object from the existing Conda environment mycondaenv. 它使用 from_existing_conda_environment() 方法。It uses the from_existing_conda_environment() method.

myenv = Environment.from_existing_conda_environment(name = "myenv",
                                                    conda_environment_name = "mycondaenv")

环境定义可以通过 save_to_directory() 方法以易于编辑的格式保存到目录。An environment definition can be saved to a directory in an easily editable format with the save_to_directory() method. 进行修改后,可以通过从目录加载文件来实例化新的环境。Once modified, a new environment can be instantiated by loading files from the directory.

myenv = Environment.save_to_directory(path = "path-to-destination-directory", overwrite = False)
# modify the environment definition
newenv = Environment.load_from_directory(path = "path-to-source-directory")

自动创建环境Create environments automatically

通过提交训练运行来自动创建环境。Automatically create an environment by submitting a training run. 使用 submit() 方法提交运行。Submit the run by using the submit() method. 提交训练运行时,生成新环境可能需要几分钟时间。When you submit a training run, the building of the new environment can take several minutes. 生成持续时间取决于所需依赖项的大小。The build duration depends on the size of the required dependencies.

如果在提交运行之前未在运行配置中指定环境,系统会自动创建一个默认环境。If you don't specify an environment in your run configuration before you submit the run, then a default environment is created for you.

from azureml.core import ScriptRunConfig, Experiment, Environment
# Create experiment 
myexp = Experiment(workspace=ws, name = "environment-example")

# Attach training script and compute target to run config
runconfig = ScriptRunConfig(source_directory=".", script="example.py")
runconfig.run_config.target = "local"

# Submit the run
run = myexp.submit(config=runconfig)

# Show each step of run 
run.wait_for_completion(show_output=True)

将包添加到环境Add packages to an environment

使用 Conda、pip 或专用 wheel 文件将包添加到环境。Add packages to an environment by using Conda, pip, or private wheel files. 使用 CondaDependency 类指定每个包依赖项。Specify each package dependency by using the CondaDependency class. 将此依赖项添加到环境的 PythonSectionAdd it to the environment's PythonSection.

Conda 和 pip 包Conda and pip packages

如果某个包已在 Conda 包存储库中提供,则相较于 pip 安装,我们更建议使用 Conda 安装。If a package is available in a Conda package repository, then we recommend that you use the Conda installation rather than the pip installation. Conda 包通常附带预生成的二进制文件,能提高安装的可靠性。Conda packages typically come with prebuilt binaries that make installation more reliable.

以下示例将其添加到环境 myenvThe following example adds to the environment myenv. 它添加了 1.17.0 版的 numpyIt adds version 1.17.0 of numpy. 它还添加 pillow 包。It also adds the pillow package. 该示例分别使用 add_conda_package() 方法和 add_pip_package() 方法。The example uses the add_conda_package() method and the add_pip_package() method, respectively.

from azureml.core.environment import Environment
from azureml.core.conda_dependencies import CondaDependencies

myenv = Environment(name="myenv")
conda_dep = CondaDependencies()

# Installs numpy version 1.17.0 conda package
conda_dep.add_conda_package("numpy==1.17.0")

# Installs pillow package
conda_dep.add_pip_package("pillow")

# Adds dependencies to PythonSection of myenv
myenv.python.conda_dependencies=conda_dep

还可以将环境变量添加到环境。You can also add environment variables to your environment. 然后,可以在训练脚本中使用 os.environ.get 让它们变得可用。These then become available using os.environ.get in your training script.

myenv.environment_variables = {"MESSAGE":"Hello from Azure Machine Learning"}

重要

如果你对另一个运行使用相同的环境定义,Azure 机器学习服务将重复使用环境的已缓存映像。If you use the same environment definition for another run, the Azure Machine Learning service reuses the cached image of your environment. 如果创建了一个包含未固定包依赖项(例如 numpy)的环境,该环境将继续使用创建环境时安装的包版本。If you create an environment with an unpinned package dependency, for example numpy, that environment will keep using the package version installed at the time of environment creation. 此外,将来包含匹配定义的任何环境将继续使用旧版本。Also, any future environment with matching definition will keep using the old version. 有关详细信息,请参阅生成、缓存和重复使用环境For more information, see Environment building, caching, and reuse.

专用 Python 包Private Python packages

若要在不将 Python 包公开到公共 Internet 的情况下以专用且安全的方式使用它们,请参阅如何使用专用 Python 包一文。To use Python packages privately and securely without exposing them to the public internet, see the article How to use private Python packages.

管理环境Manage environments

管理环境,以便可以跨计算目标以及与其他工作区用户共同更新、跟踪和重复使用这些环境。Manage environments so that you can update, track, and reuse them across compute targets and with other users of the workspace.

注册环境Register environments

在提交运行或部署 Web 服务时,环境将自动注册到工作区。The environment is automatically registered with your workspace when you submit a run or deploy a web service. 还可以使用 register() 方法手动注册环境。You can also manually register the environment by using the register() method. 此操作可让环境成为云中受到跟踪且经过版本控制的实体。This operation makes the environment into an entity that's tracked and versioned in the cloud. 可以在工作区用户之间共享该实体。The entity can be shared between workspace users.

以下代码将 myenv 环境注册到 ws 工作区。The following code registers the myenv environment to the ws workspace.

myenv.register(workspace=ws)

在训练或部署中首次使用环境时,该环境将注册到工作区。When you use the environment for the first time in training or deployment, it's registered with the workspace. 然后,它将在计算目标上生成并部署。Then it's built and deployed on the compute target. 服务将缓存环境。The service caches the environments. 与使用新服务或已更新的服务相比,重复使用已缓存的环境可以节约很多时间。Reusing a cached environment takes much less time than using a new service or one that has been updated.

获取现有环境Get existing environments

Environment 类提供一些方法用于检索工作区中的现有环境。The Environment class offers methods that allow you to retrieve existing environments in your workspace. 可按名称、以列表形式或者按特定的训练运行检索环境。You can retrieve environments by name, as a list, or by a specific training run. 此信息有助于故障排除、审核和再现。This information is helpful for troubleshooting, auditing, and reproducibility.

查看环境列表View a list of environments

使用 Environment.list(workspace="workspace_name") 类查看工作区中的环境。View the environments in your workspace by using the Environment.list(workspace="workspace_name") class. 然后选择要重复使用的环境。Then select an environment to reuse.

按名称获取环境Get an environment by name

还可以按名称和版本获取特定环境。You can also get a specific environment by name and version. 以下代码使用 get() 方法检索 ws 工作区中 myenv 环境的版本 1The following code uses the get() method to retrieve version 1 of the myenv environment on the ws workspace.

restored_environment = Environment.get(workspace=ws,name="myenv",version="1")

训练特定于运行的环境Train a run-specific environment

若要在训练完成后获取用于特定运行的环境,请使用 Run 类中的 get_environment() 方法。To get the environment that was used for a specific run after the training finishes, use the get_environment() method in the Run class.

from azureml.core import Run
Run.get_environment()

更新现有环境Update an existing environment

假设你更改了现有环境,例如,通过添加 Python 包。Say you change an existing environment, for example, by adding a Python package. 这需要时间来构建,因为在你提交运行、部署模型或手动注册环境时,系统会创建该环境的新版本。This will take time to build as a new version of the environment is then created when you submit a run, deploy a model, or manually register the environment. 版本控制让你可以查看环境在不同时间的变化。The versioning allows you to view the environment's changes over time.

若要更新现有环境中的 Python 包版本,请指定该包的版本号。To update a Python package version in an existing environment, specify the version number for that package. 如果不使用确切的版本号,Azure 机器学习会重复使用现有环境及其原始包版本。If you don't use the exact version number, then Azure Machine Learning will reuse the existing environment with its original package versions.

调试映像生成Debug the image build

以下示例使用 build() 方法将环境手动创建为 Docker 映像。The following example uses the build() method to manually create an environment as a Docker image. 它使用 wait_for_completion() 监视映像生成中的输出日志。It monitors the output logs from the image build by using wait_for_completion(). 然后,生成的映像将显示在工作区的 Azure 容器注册表实例中。The built image then appears in the workspace's Azure Container Registry instance. 此信息有助于调试。This information is helpful for debugging.

from azureml.core import Image
build = env.build(workspace=ws)
build.wait_for_completion(show_output=True)

可以首先使用 build_local() 方法在本地生成映像。It is useful to first build images locally using the build_local() method. 若要生成 docker 映像,请设置可选参数 useDocker=TrueTo build a docker image, set the optional parameter useDocker=True. 若要将生成的映像推送到 AzureML 工作区容器注册表,请设置 pushImageToWorkspaceAcr=TrueTo push the resulting image into the AzureML workspace container registry, set pushImageToWorkspaceAcr=True.

build = env.build_local(workspace=ws, useDocker=True, pushImageToWorkspaceAcr=True)

警告

更改环境中的依赖项或通道的顺序将产生新的环境,并将需要新的映像生成。Changing the order of dependencies or channels in an environment will result in a new environment and will require a new image build. 此外,如果存在新版本,则为现有映像调用 build() 方法将更新其依赖项。In addition, calling the build() method for an existing image will update its dependencies if there are new versions.

使用环境进行训练Use environments for training

若要提交训练运行,需要将你的环境、计算目标和训练 Python 脚本组合到运行配置中。To submit a training run, you need to combine your environment, compute target, and your training Python script into a run configuration. 此配置是用于提交运行的包装器对象。This configuration is a wrapper object that's used for submitting runs.

提交训练运行时,生成新环境可能需要几分钟时间。When you submit a training run, the building of a new environment can take several minutes. 具体的持续时间取决于所需依赖项的大小。The duration depends on the size of the required dependencies. 环境由服务缓存。The environments are cached by the service. 因此,只要环境定义保持不变,完整安装就只会发生一次。So as long as the environment definition remains unchanged, you incur the full setup time only once.

以下本地脚本运行示例显示应使用 ScriptRunConfig 作为包装器对象的地方。The following local script run example shows where you would use ScriptRunConfig as your wrapper object.

from azureml.core import ScriptRunConfig, Experiment
from azureml.core.environment import Environment

exp = Experiment(name="myexp", workspace = ws)
# Instantiate environment
myenv = Environment(name="myenv")

# Add training script to run config
runconfig = ScriptRunConfig(source_directory=".", script="train.py")

# Attach compute target to run config
runconfig.run_config.target = "local"

# Attach environment to run config
runconfig.run_config.environment = myenv

# Submit run 
run = exp.submit(runconfig)

备注

若要禁用运行历史记录或运行快照,请使用 ScriptRunConfig.run_config.history 下的设置。To disable the run history or run snapshots, use the setting under ScriptRunConfig.run_config.history.

如果未在运行配置中指定环境,服务将在提交运行时创建一个默认环境。If you don't specify the environment in your run configuration, then the service creates a default environment when you submit your run.

使用环境进行 Web 服务部署Use environments for web service deployment

在将模型部署为 Web 服务时,可以使用环境。You can use environments when you deploy your model as a web service. 此功能可以实现可再现的联网工作流。This capability enables a reproducible, connected workflow. 在此工作流中,可在训练计算和推理计算中使用相同的库来训练、测试和部署模型。In this workflow, you can train, test, and deploy your model by using the same libraries in both your training compute and your inference compute.

如果你要为 Web 服务部署定义自己的环境,则必须将版本不低于 1.0.45 的 azureml-defaults 列出为 pip 依赖项。If you are defining your own environment for web service deployment, you must list azureml-defaults with version >= 1.0.45 as a pip dependency. 此包包含将模型作为 Web 服务托管时所需的功能。This package contains the functionality that's needed to host the model as a web service.

若要部署 Web 服务,请将环境、推理计算、评分脚本和已注册的模型组合到部署对象 deploy() 中。To deploy a web service, combine the environment, inference compute, scoring script, and registered model in your deployment object, deploy(). 有关详细信息,请参阅部署模型的方式和位置For more information, see How and where to deploy models.

此示例假设你已完成训练运行。In this example, assume that you've completed a training run. 现在你希望将模型部署到 Azure 容器实例。Now you want to deploy that model to Azure Container Instances. 生成 Web 服务时,模型和评分文件会装载到映像上,并且 Azure 机器学习推理堆栈会添加到映像中。When you build the web service, the model and scoring files are mounted on the image, and the Azure Machine Learning inference stack is added to the image.

from azureml.core.model import InferenceConfig, Model
from azureml.core.webservice import AciWebservice, Webservice

# Register the model to deploy
model = run.register_model(model_name = "mymodel", model_path = "outputs/model.pkl")

# Combine scoring script & environment in Inference configuration
inference_config = InferenceConfig(entry_script="score.py", environment=myenv)

# Set deployment configuration
deployment_config = AciWebservice.deploy_configuration(cpu_cores = 1, memory_gb = 1)

# Define the model, inference, & deployment configuration and web service name and location to deploy
service = Model.deploy(
    workspace = ws,
    name = "my_web_service",
    models = [model],
    inference_config = inference_config,
    deployment_config = deployment_config)

笔记本Notebooks

文章介绍如何将 Conda 环境安装为笔记本中的内核。This article provides information about how to install a Conda environment as a kernel in a notebook.

使用自定义 Docker 基础映像部署模型演示了如何使用自定义的 Docker 基础映像部署模型。Deploy a model using a custom Docker base image demonstrates how to deploy a model using a custom Docker base image.

此示例笔记本演示了如何将 Spark 模型部署为 Web 服务。This example notebook demonstrates how to deploy a Spark model as a web service.

使用 CLI 创建和管理环境Create and manage environments with the CLI

Azure 机器学习 CLI 具备 Python SDK 的大部分功能。The Azure Machine Learning CLI mirrors most of the functionality of the Python SDK. 可以使用它来创建和管理环境。You can use it to create and manage environments. 本部分所讨论的命令演示了基本功能。The commands that we discuss in this section demonstrate basic functionality.

以下命令为指定目录中的默认环境定义创建基架文件。The following command scaffolds the files for a default environment definition in the specified directory. 这些文件是 JSON 文件。These files are JSON files. 其工作方式类似于 SDK 中的相应类。They work like the corresponding class in the SDK. 可以使用这些文件创建采用自定义设置的新环境。You can use the files to create new environments that have custom settings.

az ml environment scaffold -n myenv -d myenvdir

运行以下命令可从指定的目录注册环境。Run the following command to register an environment from a specified directory.

az ml environment register -d myenvdir

运行以下命令可以列出所有已注册的环境。Run the following command to list all registered environments.

az ml environment list

使用以下命令下载已注册的环境。Download a registered environment by using the following command.

az ml environment download -n myenv -d downloaddir

后续步骤Next steps