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 *
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.
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 https://github.com/perceptualrobots/pct.git
I run a script with this:
git add -A
git commit -m update
and have this in each notebook,
from nbdev import *
Since you have your notebooks inside of /nbs you need to look one level up. So it actually does make sense 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
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?