Important: IBM Cloud Pak® for Data Version 4.8 will reach end of support (EOS) on 31 July, 2025. For more information, see the Discontinuance of service announcement for IBM Cloud Pak for Data Version 4.X.
Upgrade to IBM Software Hub Version 5.1 before IBM Cloud Pak for Data Version 4.8 reaches end of support. For more information, see Upgrading from IBM Cloud Pak for Data Version 4.8 to IBM Software Hub Version 5.1.
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 template.
See Customizing environment templates.
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:
-
Add the package to your project storage by clicking the Upload asset to project icon (
), and then browsing the package file or dragging it into your notebook sidebar.
-
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()
-
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. -
Now you can import the library:
import xxx
Parent topic: Libraries and scripts