Examples of customizations

This topic shows you different examples of how to add custom libraries through conda or pip using the provided templates for Python and R when you create an environment definition.

Adding conda packages

To get latest versions of pandas-profiling:

  - pandas-profiling 

This is equivalent to running conda install pandas-profiling in a notebook.

Adding pip packages

You can also customize an environment using pip if a particular package is not available in conda channels:

  - pip:
    - watson-machine-learning-client-V4

This is equivalent to running pip install watson-machine-learning-client-V4 in a notebook.

Combining conda and pip packages

You can list multiple packages with one package per line. A single customization can have both conda packages and pip packages.

  - pandas-profiling
  - scikit-learn=0.20
  - pip:
    - watson-machine-learning-client-V4
    - sklearn-pandas==1.8.0

Note that the required template notation is sensitive to leading spaces. Each item in the list of conda packages must have two leading spaces. Each item in the list of pip packages must have four leading spaces. The version of a conda package must be specified using a single equals symbol (=), while the version of a pip package must be added using two equals symbols (==).

Adding complex packages with internal dependencies

When you add many packages or a complex package with many internal dependencies, the conda installation might take long or might even stop without you seeing any error message. To avoid this from happening:

  • Specify the versions of the packages you want to add. This reduces the search space for conda to resolve dependencies.
  • Increase the memory size of the environment.
  • Use a specific channel instead of the default conda channels that are defined in the .condarc file. This avoids running lengthy searches through big channels.

Example of a customization that doesn’t use the default conda channels:

# get latest version of the fbprophet package from the conda-forge channel
  - conda-forge    
  - nodefaults

  - fbprophet

This customization corresponds to the following command in a notebook:

!conda install -c conda-forge --override-channels fbprophet -y

Best practices

To avoid problems that can arise finding packages or resolving conflicting dependencies, start by installing the packages you need manually through a notebook in a test environment. This enables you to check interactively if packages can be installed without errors. After you have verified that the packages were all correctly installed, create a customization for your development or production environment and add the packages to the customization template.