Home > Software design >  Importing error: ModuleNotFoundError: No module named 'item'
Importing error: ModuleNotFoundError: No module named 'item'

Time:03-23

I wrote (in Jupyter) a mother class (named Item) in a file named item and saved it in this path:

'C:\\Users\\Sareh\\Desktop\\New folder\\gg\\item.ipynb'

Now I wanted to write a child class of Item, therefore importing the item.ipynb file inside the child class file. Both of the files are in the same path. The path for child class is:

'C:\\Users\\Sareh\\Desktop\\New folder\\gg\\phone.ipynb'

but I get this error:

ModuleNotFoundError: No module named 'item'

I do not know where I am doing wrong. Here is my code:

from item import Item

class phone(amir):

    def __init__(self, name:str,  price:float,quantity:int,broken_phone=0):
        super().__init__(
            name,price,quantity
        )
        assert broken_phone>=0, f"broken_Phone {broken_phone} should be positive"


phone1=phone('jj',5,6,7)

CodePudding user response:

The issue is that you are trying to import Item from an ipynb file (Jupyeter notebook file).

Importing should (and expected) to be done from Python modules, files ending with .py.

How ever you can use this question which might help you even though I would recommend using a .py to store your classes.

  • Related