How to take the advantage of both nbdev and IDE

When I was using nbdev to develop a package, I also heavily use vscode. I frequently use nbdev_update_lib and nbdev_build_lib. However, I organize my code by IDE, which cannot be converted by nbdev_update_lib. What is a good way to balance nbdev notebooks and vscode? Should I always use nbdev to write the code part?

1 Like

You might be able to run your notebooks inside of vs code with the Python extension and still use nbdev to generate the library. Having your notebooks inside VS Code as well would keep you inside your comfort IDE all the time while you can still benefit from interactive output and most of the jupyter goodness. However note that you are still stuck with jupyters shortcuts when using VS Codes notebook viewer.
The Python extension also enables you to define code cells inside a .py using comments (see here), which you can use for both interactive execution (while preserving your default code editing shortcuts) and later converting the file to an .ipynb, which you could use for nbdev. The conversion to .ipynb would probably have to be done manually tho.

I had some problems with doing autopep8 in vscode and my #Cell tag goes everywhere… Have you experienced that?

I don’t use autopep8, but I think it should not mess with comments… Maybe you can add an exception in the config?

Thanks @xeTaiz! I think it’s pylint to try to keep 2 lines of space between functions. And pylint always try to insert lines between # Cell and the function.

Can I suggest you try doing everything in your notebooks (o: In case you’ve not seen this already, it’s well worth a read.

At the risk of sounding really pushy, I’d also encourage you to adopt a more fastai coding style if possible - given time to adjust, I think you’ll prefer this style over pep8 for the kind of data science code you’re writing.

Hope this helps (o:

Thanks Pete! This is very helpful. Now I know why I have those strange error and everyone else seems fine.

Hi @ajing or @xeTaiz , did any of you try this?

My “ideal” working setup (I think) would be to allow for the interactive window with code cells inside .py in vscode and then export via notebooks to nbdev.

Notebooks are good, but I often want to jump into functions and run parts of them (for debugging), and then its a pain to have to create new cells + deleting ++. Cant figure out a good way to do that in notebooks…

Ive made one attempt on this using nbconvert, but the notebooks did not turn out nice. I am sure it should be possible with sufficient bickering, but if there is sucess elsewhere Id like to check that first :slight_smile:

Hey there,
I remember that I had success with nbconvert on a VS code produced ipynb in the past, but I haven’t tried with complex examples.
I’m currently not using nbdev, rather a combination of developing library code inside VS code, testing and visualizing through Jupyter notebooks. But if you dive deeper into this I’m very curious for the results, I just haven’t found the time to implement this pipeline for a bigger project.

yes, I guess some conversion stuff and an extra layer can work, but not sure if the flow is perfect. Will let you know if I do any more on this

There is also lib2nbdev and I’m also writing nbagile to directly tackle this

1 Like

With the recently updated Notebooks in VSCode, nbdev works just as well with VSCode as using JupyterLab or Jupyter Notebooks.

1 Like

but you are still working in notebooks? I am constrained to not the most recent vscode :confused:

Yes. I’ve created some PRs for with nbdev using VSCode notebooks via WSL, and am developing my own small fastai extensions library using nbdev with VSCode notebooks.