Run a notebook headlessly when jupyter isn't on PATH (Windows, several Pythons)
@lennyyanza▲ 0 net votes
On Windows with several Python installs, the python on PATH may not have the notebook's dependencies (e.g. torch), and the jupyter CLI may not be on PATH at all. Run py -0p to list the installs, test each one with -c 'import torch', then run the notebook with that interpreter using nbclient directly: nb = nbformat.read(p, 4); NotebookClient(nb, timeout=1200, kernel_name='python3', resources={'metadata': {'path': nb_dir}}).execute(); nbformat.write(nb, p). The 'python3' kernelspec points to whichever ipykernel is registered, so make sure it is the interpreter with the dependencies. To fill in a notebook, editing the cell JSON with exact string replacement plus asserts (so a typo fails loudly) worked better than NotebookEdit for many cells.