Import errors in auto created module

My main nbdev directory contains two notebooks, class_dataset.ipynb and class_training.ipynb and I’ve successfully used the notebook2script() function to convert the notebooks into scripts inside a “scripts” directory. Inside of the class_training notebook I have “from scripts.class_dataset import *” and inside the corresponding script that is converted to “from .class_dataset import *” as one would expect. Also, within the class_training notebook I have a block that starts with if name == “main”: so that the module can be ran as a script. Everything works fine when I run the code from within the notebook, but when I do a “python class_training.py” from the command line I get the following:

File “scripts/class_training.py”, line 10, in
from .class_dataset import *
ImportError: attempted relative import with no known parent package

I’ve read what I think is the relevant nbdev documentation and the python documentation for modules and running modules as scripts. It seems like everything is set up correctly. What am I doing wrong?

1 Like

Are you sure you have a __init__.py in your scripts directory?

Yeah, that’s autogenerated by nbdev. I just figured out what I was doing wrong. Instead of “python class_training.py” I have to execute “python -m scripts.class_training” from within the top level directory that the notebooks live in.

2 Likes

I use spyder to access and run scripts. And spyder runs the scripts from inside the scripts directory. Is there a way, I can run scripts from inside spyder ide ?