CondaDependencies Class

Manages application dependencies in an Azure Machine Learning environment.

Note

If no parameters are specified, azureml-defaults is added as the only pip dependency.

If the conda_dependencies_file_path parameter is not specified, then the CondaDependencies object contains only the Azure Machine Learning packages (azureml-defaults). The azureml-defaults dependency will not be pinned to a specific version and will target the latest version available on PyPi.

Initialize a new object to manage dependencies.

Inheritance
builtins.object
CondaDependencies

Constructor

CondaDependencies(conda_dependencies_file_path=None, _underlying_structure=None)

Parameters

conda_dependencies_file_path
str
default value: None

A local path to a conda configuration file. Using this parameter allows for loading and editing of an existing Conda environment file.

_underlying_structure
default value: None

Remarks

You can load an existing conda environment file or choose to configure and manage the application dependencies in memory. During experiment submission, a preparation step is executed which creates and caches a conda environment within which the experiment executes.

If your dependency is available through both Conda and pip (from PyPi), use the Conda version, as Conda packages typically come with pre-built binaries that make installation more reliable. For more information, see Understanding Conda and Pip.

See the repository https://github.com/Azure/AzureML-Containers for details on base image dependencies.

The following example shows how to add a package using the add_conda_package.


   from azureml.core.authentication import MsiAuthentication

   msi_auth = MsiAuthentication()

   ws = Workspace(subscription_id="my-subscription-id",
                  resource_group="my-ml-rg",
                  workspace_name="my-ml-workspace",
                  auth=msi_auth)

   print("Found workspace {} at location {}".format(ws.name, ws.location))

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/manage-azureml-service/authentication-in-azureml/authentication-in-azureml.ipynb

A pip package can also be added and the dependencies set in the Environment object.


   conda_dep.add_pip_package("pillow==6.2.1")
   myenv.python.conda_dependencies=conda_dep

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/training/using-environments/using-environments.ipynb

Methods

add_channel

Add a conda channel.

A list of channels can be found at https://docs.anaconda.com/anaconda/user-guide/tasks/using-repositories/

add_cntk_package

Add a Microsoft Cognitive Toolkit (CNTK) package.

add_conda_package

Add a conda package.

add_pip_package

Add a pip package.

Note

Adding a dependency of an already referenced package will remove the previous reference and add a new reference to the end of the dependencies list. This may change the order of the dependencies.

add_tensorflow_conda_package

Add a Tensorflow conda package.

add_tensorflow_pip_package

Add a Tensorflow pip package.

as_dict

Return conda dependecies.

create

Initialize a new CondaDependencies object.

Returns an instance of a CondaDependencies object with user specified dependencies.

Note

If pip_packages is not specified, azureml-defaults will be added as the default dependencies. User specified pip_packages dependencies will override the default values.

If pin_sdk_version is set to true, pip dependencies of the packages distributed as a part of Azure Machine Learning Python SDK will be pinned to the SDK version installed in the current environment.

get_default_number_of_packages

Return the default number of packages.

get_python_version

Return the Python version.

merge_requirements

Merge package requirements.

remove_channel

Remove a conda channel.

remove_conda_package

Remove a conda package.

remove_pip_option

Remove a pip option.

remove_pip_package

Remove a pip package.

save

Save the conda dependencies object to file.

save_to_file

DEPRECATED, use save.

Save the conda dependencies object to file.

sdk_origin_url

Return the SDK origin index URL.

serialize_to_string

Serialize conda dependencies object into a string.

set_pip_index_url

Set pip index URL.

set_pip_option

Add a pip option.

set_pip_requirements

Overwrite the entire pip section of conda dependencies.

set_python_version

Set the Python version.

add_channel

Add a conda channel.

A list of channels can be found at https://docs.anaconda.com/anaconda/user-guide/tasks/using-repositories/

add_channel(channel)

Parameters

channel
str
Required

The conda channel to add.

Return type

add_cntk_package

Add a Microsoft Cognitive Toolkit (CNTK) package.

add_cntk_package(core_type='cpu')

Parameters

core_type
str
default value: cpu

'cpu' or 'gpu'.

add_conda_package

Add a conda package.

add_conda_package(conda_package)

Parameters

conda_package
str
Required

The conda package to add.

add_pip_package

Add a pip package.

Note

Adding a dependency of an already referenced package will remove the previous reference and add a new reference to the end of the dependencies list. This may change the order of the dependencies.

add_pip_package(pip_package)

Parameters

pip_package
str
Required

The pip package to be add.

add_tensorflow_conda_package

Add a Tensorflow conda package.

add_tensorflow_conda_package(core_type='cpu', version=None)

Parameters

core_type
str
default value: cpu

'cpu' or 'gpu'.

version
str
default value: None

The package version.

add_tensorflow_pip_package

Add a Tensorflow pip package.

add_tensorflow_pip_package(core_type='cpu', version=None)

Parameters

core_type
str
default value: cpu

'cpu' or 'gpu'.

version
str
default value: None

The package version.

as_dict

Return conda dependecies.

as_dict() -> Any

create

Initialize a new CondaDependencies object.

Returns an instance of a CondaDependencies object with user specified dependencies.

Note

If pip_packages is not specified, azureml-defaults will be added as the default dependencies. User specified pip_packages dependencies will override the default values.

If pin_sdk_version is set to true, pip dependencies of the packages distributed as a part of Azure Machine Learning Python SDK will be pinned to the SDK version installed in the current environment.

static create(pip_indexurl=None, pip_packages=None, conda_packages=None, python_version='3.8.13', pin_sdk_version=True)

Parameters

pip_indexurl
str
default value: None

The pip index URL. If not specified, the SDK origin index URL will be used.

pip_packages
list[str]
default value: None

A list of pip packages.

conda_packages
list[str]
default value: None

A list of conda packages.

python_version
str
default value: 3.8.13

The Python version.

pin_sdk_version
bool
default value: True

Indicates whether to pin SDK packages to the client version.

Returns

A conda dependency object.

Return type

get_default_number_of_packages

Return the default number of packages.

get_default_number_of_packages()

Returns

The default number of conda and pip packages.

Return type

int

get_python_version

Return the Python version.

get_python_version()

Returns

The Python version.

Return type

str

merge_requirements

Merge package requirements.

static merge_requirements(requirements)

Parameters

requirements
list[str]
Required

A list of packages requirements to merge.

Returns

A list of merged package requirements.

Return type

remove_channel

Remove a conda channel.

remove_channel(channel)

Parameters

channel
str
Required

The conada channel to remove.

remove_conda_package

Remove a conda package.

remove_conda_package(conda_package)

Parameters

conda_package
str
Required

The conda package to remove.

remove_pip_option

Remove a pip option.

remove_pip_option(pip_option)

Parameters

pip_option
str
Required

The pip option to remove.

remove_pip_package

Remove a pip package.

remove_pip_package(pip_package)

Parameters

pip_package
str
Required

The pip package to remove.

save

Save the conda dependencies object to file.

save(path=None)

Parameters

path
str
default value: None

The fully qualified path of the file you want to save to.

Returns

The normalized conda path.

Return type

str

Exceptions

Raised for issues saving the dependencies.

save_to_file

DEPRECATED, use save.

Save the conda dependencies object to file.

save_to_file(base_directory, conda_file_path=None)

Parameters

base_directory
str
Required

The base directory to save the file.

conda_file_path
str
default value: None

The file name.

Returns

The normalized conda path.

Return type

str

sdk_origin_url

Return the SDK origin index URL.

static sdk_origin_url()

Returns

Returns the SDK origin index URL.

Return type

str

serialize_to_string

Serialize conda dependencies object into a string.

serialize_to_string()

Returns

The conda dependencies object serialized into a string.

Return type

str

set_pip_index_url

Set pip index URL.

set_pip_index_url(index_url)

Parameters

index_url
str
Required

The pip index URL to use.

set_pip_option

Add a pip option.

set_pip_option(pip_option)

Parameters

pip_option
str
Required

The pip option to add.

set_pip_requirements

Overwrite the entire pip section of conda dependencies.

set_pip_requirements(pip_requirements)

Parameters

pip_requirements
list[str]
Required

The list of pip packages and options.

set_python_version

Set the Python version.

set_python_version(version)

Parameters

version
str
Required

The Python version to add.

Return type

Attributes

conda_channels

Return conda channels.

Returns

Returns the channel dependencies. The returned dependencies are a copy, and any changes to the returned channels won't update the conda channels in this object.

Return type

conda_packages

Return conda packages.

Returns

Returns the package dependencies. Returns a copy of conda packages, and any edits to the returned list won't be reflected in the conda packages of this object.

Return type

pip_options

Return pip options.

Returns

Returns the pip options. Returns a copy of pip options, and any edits to the returned list won't be reflected in the pip options of this object.

Return type

pip_packages

Return pip dependencies.

Returns

Returns the pip dependencies. Returns a copy of pip packages, and any edits to the returned list won't be reflected in the pip packages of this object.

Return type

DEFAULT_NUMBER_OF_CONDA_PACKAGES

DEFAULT_NUMBER_OF_CONDA_PACKAGES = 0

DEFAULT_NUMBER_OF_PIP_PACKAGES

DEFAULT_NUMBER_OF_PIP_PACKAGES = 0