Installing custom libraries
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 an environment. However, you can’t use the customization template if you want to install packages from somewhere else or packages you created on your local machine, for example. These packages must be installed and imported through the notebook.
To install packages other than Conda or PyPi packages through your notebook:
- Add the package to your object storage by clicking the Find and Add Data icon (), and then browsing the package file or dragging it into your notebook sidebar.
Add a project token to the notebook by clicking More > Insert project token from the notebook action bar. The code that is generated by this action initializes the variable
project, which is required to access the library you uploaded to object storage.
Example of an inserted project token:
# @hidden_cell # The project token is an authorization token that is used to access project resources like data sources, connections, and used by platform APIs. from project_lib import Project project = Project(project_id='7c7a9455-1916-4677-a2a9-a61a75942f58', project_access_token='p-9a4c487075063e610471d6816e286e8d0d222141') pc = project.project_context
If you don’t have a token, you need to create one. See Adding a project token.
- Install the library:
# Fetch the library file, for example the tar.gz or whatever installable distribution you created with open("xxx-0.1.tar.gz","wb") as f: f.write(project.get_file("xxx-0.1.tar.gz").read()) # Install the library !pip install xxx-0.1.tar.gz
- Now you can import the library: