Installing custom libraries through notebooks (Watson Studio)

The prefered way of installing additional Python libraries to use in a notebook is to customize the software configuration of the environment runtime associated with the notebook. You can add the conda or PyPi packages through a customization template when you customize the environment definition.

See Customizing environment definitions.

However, if you want to install packages from somewhere else or packages you created on your local machine, for example, you can install and import the packages through the notebook.

To install packages other than conda or PyPi packages through your notebook:

  1. Add the package to your project storage by clicking the Find and Add Data icon (Shows the find data icon), and then browsing the package file or dragging it into your notebook sidebar.
  2. In a code cell in your notebook, initialize ibm-watson-studio-lib. This library is required to access the package file you uploaded to the project storage.
     # Initialize ibm-watson-studio-lib
     from ibm_watson_studio_lib import access_project_or_space
     wslib = access_project_or_space()
    
  3. Install the library:

     # Download the file to the file system of your notebook's runtime container
     wslib.download_file("xxx-0.1.tar.gz")
     # Install and import the library
     !pip install xxx-0.1.tar.gz
    

    If your Cloud Pak for Data cluster doesn't have access to the internet, you have to provide all dependecies using !pip install --find-link . xxx-0.1.tar.gz. If you want to install additional dependencies from an internal pip index instead, use the -i option.

    Dependencies can be internal packages or publicly available ones. Packages from pypi.org can be downloaded using !pip download <package> if the Python installation has access to the internet. You should make sure that the Python version of the installation that has access to the internet matches the Python version in the Cloud Pak for Data environment.

  4. Now you can import the library:
     import xxx
    

Parent topic: Libraries and scripts