cancel
Showing results for 
Search instead for 
Did you mean: 
nataliia_kh
Sisense Team Member
Sisense Team Member
Use case

You have specific libraries in Notebooks that have to be installed to run Custom code tables. However, these libraries can be uninstalled automatically (during upgrade or other system changes).

Solution

Add the following Python code into the first cell of each Custom Table Notebook to check if necessary libraries exist and install them if not, before executing the code:

Adjust 'libraries' values to the libraries you need to check.

 

 

 

 

 

import importlib
import pandas as pd

# List the libraries you want to check
libraries = ['numpy', 'pandas', 'matplotlib', 'openpyxl', 'scipy', 'pyarrow']

# Initialize an empty list to store results
results = []

for library in libraries:
lib_found = importlib.util.find_spec(library)
if lib_found is not None:
results.append({"library": library, "status": "Previously Installed"})
else:
results.append({"library": library, "status": "Newly Installed"})
print(f"{library} NOT FOUND. Installing now...")
!pip install {library}

 

 

 

Related Content:

Sisense Docs: https://docs.sisense.com/main/SisenseLinux/transforming-data-with-custom-code.htm

Sisense Academy: https://academy.sisense.com/notebooks-course 

Rate this article:
Version history
Last update:
‎12-09-2024 12:22 PM
Updated by:
Contributors