import nbdev
nbdev.__version__
'2.3.12'
April 25, 2023
I use nbdev to write python libraries (I will create a blog entry explaining that).
And used it to blog (now only using quarto)
Sometimes you need something lighter just to export part of notebooks and reused it elsewhere (in another notebook for example).
In the old time of fastai, I used a script from Jeremy Howard (see Generate python modules from jupyter notebooks)
I want to update this method and use nbdev.
Have nbdev installed in your environment, and update it if needed
Just re-run conda install -c fastai nbdev
Start from a notebook, and
#|default_exp app
in a cell of your notebook, where app is the name of the module to be extracted#| export
in each cell you want to extractExecute the notebook, it will create an app.py
file in path
One can use this in another notebook:
from the same directory just by importing this script: import app
from a different directory by setting syspath:
import os, sys
from pathlib import Path
home = str(Path.home())
sys.path.append(os.path.abspath(os.path.join(home, 'path')))
and then import app