Serious issue with nbdev

I have a serious reoccuring issue with nbdev, that is making it unusable.

I am unable to import functions from one of my other notebooks.

My notebooks are in nbs. I have one notebook 01_putils.ipynb which has the class UniqueNamer.

When I import “from pct.putils import UniqueNamer” from notebook 02_functions.ipynb I get this error

----> 8 from pct.putils import UniqueNamer
ModuleNotFoundError: No module named ‘pct.putils’

lib_name = pct

What is the official way of resolving this?

And you have #default_exp putils at the top of 01_putils?

Well, I have this,

from nbdev import *
%nbdev_default_export putils

which gives the output “Cells will be exported to pct.putils”

Isn’t that the same thing?

Yes that’s the equivalent magic. As long as you’ve built the library then putils should be available to import from the other notebook.

Check the pct folder inside your main project root and look at the .py files it’s generated to make sure everything looks ok?

Well, I completely uninstalled the environments and Anaconda, reinstalled, recreated the virtual environment and imported nbdev and the other python packages.

Then I added this cell to every notebook and it is now working.

# hide
import sys

Not sure why though as it was working previously without this.

That makes zero sense. What’s in the grandparent directory of your notebooks which would make the slightest difference to it working or not??

I don’t know. I note that the imports in the .py files are missing “pct” like this,

from .putils import UniqueNamer

Is that normal?

Is it possible for you to share your repo with us, as I’m having some issues following what’s going on as well

Also: we are running nbdev_build_lib before trying to import your other modules right?

Sure, it is

I run a script with this:

nbdev_build_docs --fname=[0]*.ipynb
git add -A
git commit -m update

and have this in each notebook,

from nbdev import *

1 Like

Since you have your notebooks inside of /nbs you need to look one level up. So it actually does make sense :slight_smile: if you just had your nbs at the same level as your library (in a directory level perspective) then it wouldn’t be needed (I have to do the same with fastai and my other libraries)

Then shouldn’t he have to add .. to the path instead of ... ??

Actually it is ‘..’ seems you have to escape dots to get them to display properly here :slight_smile:

1 Like

Ok, now it makes sense :slightly_smiling_face:

I spoke too soon.

It had been failing on my laptop. However, this weekend I had been on my desktop, and had got it working.

But when I reverted today to my laptop I still get the ModuleNotFoundError, even after having reinstalled Anaconda, virtual environments and nbdev and other python packages.

The code and notebooks (github clone) are on a google drive, so the same code folder for both machines.

Is there some environmental variable which might be different between the two systems, that is used by nbdev?