About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
Last updated: Jan 28, 2025
Follow the examples that show how to add custom libraries through
or conda
when you create an environment template, by using the provided templates for Python and R.pip
Note:
- You can use
in place ofmamba
in the following examples. Remember to select the checkbox to install fromconda
if you add channels or packages frommamba
to the existing environment template.mamba
- The process of creating custom watsonx.ai Runtime deployment runtimes might be different. If you want to create custom watsonx.ai Runtime deployment runtimes see Customizing watsonx.ai Runtime deployment runtimes.
Examples exist for:
- Adding conda packages
- Adding pip packages
- Combining conda and pip packages
- Adding complex packages with internal dependencies
- Adding conda packages for R notebooks
- Setting environment variables
Hints and tips:
Adding conda packages
To get latest versions of pandas-profiling:
dependencies: - pandas-profiling
This is equivalent to running
in a notebook.conda install pandas-profiling
Adding pip packages
You can also customize an environment using
if a particular package is not available in pip
channels:conda
dependencies: - pip: - ibm_watsonx_ai
This is equivalent to running
in a notebook.pip install ibm_watsonx_ai
The customization will actually do more than just install the specified
package. The default behavior of pip
is to also look for a new version of conda
itself and then install it. Checking all the implicit
dependencies in pip
often takes several minutes and also gigabytes of memory. The following customization will shortcut the installation of conda
:pip
channels: - empty - nodefaults dependencies: - pip: - ibm_watsonx_ai
The
channel conda
does not provide any packages. There is no empty
package in particular. pip
won't try to install conda
and will use the already pre-installed version instead.
Note that the keyword pip
in the list of channels needs at least one other channel in the list. Otherwise nodefaults
will silently ignore the keyword and use the default channels.conda
Combining conda and pip packages
You can list multiple packages with one package per line. A single customization can have both
packages and conda
packages.pip
dependencies: - pandas-profiling - scikit-learn=0.20 - pip: - ibm_watsonx_ai - sklearn-pandas==1.8.0
Note that the required template notation is sensitive to leading spaces. Each item in the list of
packages must have two leading spaces. Each item in the list of conda
packages must have four leading spaces. The
version of a pip
package must be specified using a single equals symbol (conda
), while the version of a =
package must be added using two equals symbols (pip
).==
Adding complex packages with internal dependencies
When you add many packages or a complex package with many internal dependencies, the
installation might take long or might even stop without returning any error messages. To avoid this:conda
- Specify the versions of the packages that you want to add. This reduces the search space for
to resolve dependencies.conda
- Increase the memory size of the environment.
- Use a specific channel instead of the default
channels that are defined in theconda
file. This avoids running lengthy searches through large channels..condarc
Example of a customization that doesn't use the default
channels:conda
# get latest version of the prophet package from the conda-forge channel
channels:
- conda-forge
- nodefaults
dependencies:
- prophet
This customization corresponds to the following command in a notebook:
!conda install -c conda-forge --override-channels prophet -y
Adding conda packages for R notebooks
The following example shows you how to create a customization that adds
packages to use in an R notebook:conda
channels: - defaults dependencies: - r-plotly
This customization corresponds to the following command in a notebook:
print(system("conda install r-plotly", intern=TRUE))
The names of R packages in
generally start with the prefix conda
. If you just use r-
in your customization, the installation would succeed but the Python package would be installed instead of the
R package. If you then try to use the package in your R code as in plotly
, this would return an error.library(plotly)
Setting environment variables
You can set environment variables in your environment by adding a
section to the software customization template as shown in the following example:variables
variables: my_var: my_value HTTP_PROXY: https://myproxy:3128 HTTPS_PROXY: https://myproxy:3128 NO_PROXY: cluster.local
The example also shows that you can use the
section to set a proxy server for an environment.variables
Limitation: You cannot override existing environment variables, for example
, by using this approach.LD_LIBRARY_PATH
Best practices
To avoid problems with missing packages and conflicting dependencies, start by manually installing the packages that you need through a notebook in a test environment. This way you can interactively check if packages can be installed without errors. After you verify that the packages are correctly installed, create a customization for your development or production environment and add the packages to the customization template.
Parent topic: Customizing environments