0

I use python 3.5 with Anaconda (python 3.6) and I have a problem with importing a class within the same folder, even though I did exactly as explained in other places.

In 04-Convolutional Neural Network Folder I have 04-Convolutional Neural Network.ipynb and logger.ipynb files.

I want to import Logger class in logger.ipynbto 04-Convolutional Neural Network.ipynb

First, I created a blank __init__.ipynb file in the same folder, I used:

from .user import User
from .dir import Dir

But I get the following error

No module named '__main__.user'; '__main__' is not a package

Any idea why do I have this problem? maybe because of the ipynb file system?

Edit: The files are in Desktop/NN/.... if it's important

Niminim
  • 668
  • 1
  • 7
  • 16
  • Possible duplicate of [ipynb import another ipynb file](https://stackoverflow.com/questions/20186344/ipynb-import-another-ipynb-file) – Kirk Broadhurst Jan 17 '18 at 19:31
  • Importing `ipynb` files isn't the same as importing regular `py` files. See the duplicate link above - also refer [to this page on jupyter.org](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/docs/source/examples/Notebook/Importing%20Notebooks.ipynb) – Kirk Broadhurst Jan 17 '18 at 19:33

1 Answers1

0

It seems to refer to the file your running (namely main). I don't use relative import much. But if user and dir are in the same directory as the file your running you should try (i.e. they are in the root of your python module):

from user import User
from dir import Dir

You should probably also rename the dir module, as dir is a builtin function in python.

9000
  • 39,899
  • 9
  • 66
  • 104
ritchie46
  • 10,405
  • 1
  • 24
  • 43