Python – Module Not Found


I am a beginner with Python. Before I start, here’s my Python folder structure


Under src I have a folder named model which has a Python file called which contents follow:

class SellOrder(object):
    def __init__(self,genericName,brandName):
        self.genericName = genericName
        self.brandName = brandName

Next my is inside the src folder, one level above

import model.order.SellOrder

order = SellOrder("Test","Test")

print order.brandName

Whenever I run python it results in the error

Traceback (most recent call last):
  File "", line 1, in <module>
    import model.order.SellOrder
ImportError: No module named model.order.SellOrder

Is there anything I missed?


All modules in Python have to have a certain directory structure. You can find details here.

Create an empty file called under the model directory, such that your directory structure would look something like that:

└── project
    └── src
        └── model

Also in your file change the import statement to the following:

from model.order import SellOrder

That should fix it

P.S.: If you are placing your model directory in some other location (not in the same directory branch), you will have to modify the python path using sys.path.


Leave a Reply

Your email address will not be published. Required fields are marked *