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.objectCondaDependencies
Constructor
CondaDependencies(conda_dependencies_file_path=None, _underlying_structure=None)
Parameters
Name | Description |
---|---|
conda_dependencies_file_path
|
A local path to a conda configuration file. Using this parameter allows for loading and editing of an existing Conda environment file. Default value: None
|
_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
Name | Description |
---|---|
channel
Required
|
The conda channel to add. |
Returns
Type | Description |
---|---|
add_cntk_package
Add a Microsoft Cognitive Toolkit (CNTK) package.
add_cntk_package(core_type='cpu')
Parameters
Name | Description |
---|---|
core_type
|
'cpu' or 'gpu'. Default value: cpu
|
add_conda_package
Add a conda package.
add_conda_package(conda_package)
Parameters
Name | Description |
---|---|
conda_package
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
Name | Description |
---|---|
pip_package
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
Name | Description |
---|---|
core_type
|
'cpu' or 'gpu'. Default value: cpu
|
version
|
The package version. Default value: None
|
add_tensorflow_pip_package
Add a Tensorflow pip package.
add_tensorflow_pip_package(core_type='cpu', version=None)
Parameters
Name | Description |
---|---|
core_type
|
'cpu' or 'gpu'. Default value: cpu
|
version
|
The package version. Default value: None
|
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.9.12', pin_sdk_version=True)
Parameters
Name | Description |
---|---|
pip_indexurl
|
The pip index URL. If not specified, the SDK origin index URL will be used. Default value: None
|
pip_packages
|
A list of pip packages. Default value: None
|
conda_packages
|
A list of conda packages. Default value: None
|
python_version
|
The Python version. Default value: 3.9.12
|
pin_sdk_version
|
Indicates whether to pin SDK packages to the client version. Default value: True
|
Returns
Type | Description |
---|---|
A conda dependency object. |
get_default_number_of_packages
Return the default number of packages.
get_default_number_of_packages()
Returns
Type | Description |
---|---|
The default number of conda and pip packages. |
get_python_version
merge_requirements
Merge package requirements.
static merge_requirements(requirements)
Parameters
Name | Description |
---|---|
requirements
Required
|
A list of packages requirements to merge. |
Returns
Type | Description |
---|---|
A list of merged package requirements. |
remove_channel
Remove a conda channel.
remove_channel(channel)
Parameters
Name | Description |
---|---|
channel
Required
|
The conada channel to remove. |
remove_conda_package
Remove a conda package.
remove_conda_package(conda_package)
Parameters
Name | Description |
---|---|
conda_package
Required
|
The conda package to remove. |
remove_pip_option
Remove a pip option.
remove_pip_option(pip_option)
Parameters
Name | Description |
---|---|
pip_option
Required
|
The pip option to remove. |
remove_pip_package
Remove a pip package.
remove_pip_package(pip_package)
Parameters
Name | Description |
---|---|
pip_package
Required
|
The pip package to remove. |
save
Save the conda dependencies object to file.
save(path=None)
Parameters
Name | Description |
---|---|
path
|
The fully qualified path of the file you want to save to. Default value: None
|
Returns
Type | Description |
---|---|
The normalized conda path. |
Exceptions
Type | Description |
---|---|
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
Name | Description |
---|---|
base_directory
Required
|
The base directory to save the file. |
conda_file_path
|
The file name. Default value: None
|
Returns
Type | Description |
---|---|
The normalized conda path. |
sdk_origin_url
Return the SDK origin index URL.
static sdk_origin_url()
Returns
Type | Description |
---|---|
Returns the SDK origin index URL. |
serialize_to_string
Serialize conda dependencies object into a string.
serialize_to_string()
Returns
Type | Description |
---|---|
The conda dependencies object serialized into a string. |
set_pip_index_url
Set pip index URL.
set_pip_index_url(index_url)
Parameters
Name | Description |
---|---|
index_url
Required
|
The pip index URL to use. |
set_pip_option
Add a pip option.
set_pip_option(pip_option)
Parameters
Name | Description |
---|---|
pip_option
Required
|
The pip option to add. |
set_pip_requirements
Overwrite the entire pip section of conda dependencies.
set_pip_requirements(pip_requirements)
Parameters
Name | Description |
---|---|
pip_requirements
Required
|
The list of pip packages and options. |
set_python_version
Set the Python version.
set_python_version(version)
Parameters
Name | Description |
---|---|
version
Required
|
The Python version to add. |
Returns
Type | Description |
---|---|
Attributes
conda_channels
Return conda channels.
Returns
Type | Description |
---|---|
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. |
conda_packages
Return conda packages.
Returns
Type | Description |
---|---|
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. |
pip_options
Return pip options.
Returns
Type | Description |
---|---|
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. |
pip_packages
Return pip dependencies.
Returns
Type | Description |
---|---|
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. |
DEFAULT_NUMBER_OF_CONDA_PACKAGES
DEFAULT_NUMBER_OF_CONDA_PACKAGES = 0
DEFAULT_NUMBER_OF_PIP_PACKAGES
DEFAULT_NUMBER_OF_PIP_PACKAGES = 0