Get installs
Tags: #jupyternotebooks #naas #jupyter-notebooks #read #installs #snippet #operations #text
Description: This notebook provides instructions for installing Jupyter Notebooks.
import json
from pprint import pprint
# Input
notebook_path = "../template.ipynb"
def get_installs(notebook_path):
with open(notebook_path) as f:
nb = json.load(f)
data = []
cells = nb.get("cells")
# Check each cells
for cell in cells:
cell_type = cell.get("cell_type")
sources = cell.get("source")
for source in sources:
if cell_type == "code":
if "pip install" in source:
install = source.split("pip install")[-1].replace("\n", "").strip()
data.append(install)
if len(data) == 0:
print("❎ No install found in notebook:", notebook_path)
else:
print(f"✅ {len(data)} install(s) found in notebook:", notebook_path)
return data
installs = get_installs(notebook_path)
print(installs)
Last modified 1mo ago