I noticed something odd about using notebook2script.py
and run_notebook.py
on the command line vs. in a notebook. I’m not 100% sure if this isn’t due to my env or not.
I can run run_notebook.py
from the command line only if I use a registered ipykernel in the target notebook. However, within a notebook I can only run notebook2script.py
if I am using an auto-generated kernel.
I’m using auto-generated ipykernels (I think with nb_conda?) – so any conda env you have will show up as a kernel, without requiring you to manually register each one with:
(envname) $ python -m ipykernel install --name "envname"
Now, if I set the kernel as the auto-gen’d one, I can’t run run_notebook.py
on command line because it can’t find conda-env-fastai-py
, the name of the auto-gen’d kernel. This kind of makes sense, and from what I read seems like a current Jupyter limitation.
The confusing bit, is that I can’t run a cell containing
!python notebook2script.py 01_matmul-Copy1.ipynb
in my 01_matmul-Copy1
notebook without using the auto-gen’d kernel. If I use my registered fastai
kernel, I get:
Traceback (most recent call last):
File "notebook2script.py", line 3, in <module>
import json,fire,re
ModuleNotFoundError: No module named 'fire'
My guess is that the #!/usr/bin/env python
line in run_notebook.py
is pointing to my base Python (which doesn’t have fire), but when it’s run with the auto-gen’d kernel, something somewhere is ‘tricked’ into treating my fastai env as base Python, and thus: no errors.
NOTE: If I find a solution I’ll post here; the running solution is to use a registered kernel when running from the command line, and an nb_conda auto-gen’d kernel when running from a cell in a notebook.
Early command-line testing before I discovered the in-notebook failure case:
notebook : 00_exports-Copy1.ipynb
$ notebook2script.py 00_exports-Copy1.ipynb
$ python run_notebook.py 00_exports-Copy1.ipynb
env : Python [conda env:fastai]
- run_notebook.py — FAIL
- notebook2script.py — PASS
env : fastai
- run_notebook.py — PASS
- notebook2script.py — PASS
notebook : 01_matmul-Copy1.ipynb
env : fastai
- run_notebook.py — PASS
- notebook2script.py — PASS