Problem with nbdev and notebook2script

Hi, I have a problem with nbdev and notebook2script . I have installed the following versions: nbdev 2.3.6; notebook2script 0.2.1.
When I try to run from nbdev.export import notebook2script I get the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [30], in <cell line: 1>()
----> 1 from nbdev.export import notebook2script

ImportError: cannot import name 'notebook2script' from 'nbdev.export' (/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/nbdev/export.py)

Has anyone solved this problem?
Thanks

1 Like

You may want to refer the migration guide especially update directive names nbdev - nbdev1 Migration

As suggested here:

import nbdev
nbdev.export.nb_export('app.ipynb', 'app')
print('Export successful')
10 Likes

Thank you @chrwittm, I had trouble with that! :slightly_smiling_face:
I’ll add that the 2nd parameter to nb_export is the directory path and not the filename, so if you wish to create the Python file directly in the same dir as your notebook, you can do this:
nbdev.export.nb_export('app.ipynb', './')

9 Likes

Documenting an error I ran into.

You might see
ExportModuleProc._default_exp_() missing 1 required positional argument: 'exp_to' if you’ve called #|default_exp without a filename. So just run the cell again as #|default_exp app and then nbdev.export.nb_export('app.ipynb').

1 Like
# Export Notebook to python Script -- nbdev --
from notebook2script import convert_notebook
convert_notebook('Lesson-2.ipynb','app.py')

This is one of the solution I did found while experimenting

And I would like to add to @chrwittm and @dway8 comments that if it’s running without error but it’s not creating any .py file for you, it’s because you need to install JupyterLab Extension. If you are using pip you can run below:
pip install jupyterlab-quarto
Here is the link for other ways of its installation:

I have the same problem with notebook2script. Kaggle does not run it and locally it is not working after conda installations and pip installations.
The above solution did not work. to uninstall do

py -m pip uninstall jupyterlab-quarto

ImportError Traceback (most recent call last)
Cell In[126], line 1
----> 1 from nbdev.export import notebook2script
3 notebook2script(‘app.app.ipynb’)

ImportError: cannot import name ‘notebook2script’ from ‘nbdev.export’ (/opt/conda/lib/python3.10/site-packages/nbdev/export.py)

!jupyter nbconvert --to script app.ipynb tried this from kaggle but no luck.