1

I'm trying to run a script test1.py which calls model.py. However I encounter an import error when Python tries to import module.py from within model.py. How can I get test1.py to find this?

├── model
├     ├── model.py
├     └── module.py
└─── tests  
      └── test1.py
    

In test1.py

from model.model import blah

In model.py

import module

When I run test1.py, Python complains that it can't see module.py:

ModuleNotFoundError: No module named 'module'

FYI I am working in Python3

pinnochio
  • 326
  • 3
  • 9

1 Answers1

0

You have to try like this import .model

or you have to add __init__.py file inside your model directory.

Here you go for python docks for __init__.py

Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory containing an __init__.py file. When a regular package is imported, this __init__.py file is implicitly executed, and the objects it defines are bound to names in the package’s namespace. The __init__.py file can contain the same Python code that any other module can contain, and Python will add some additional attributes to the module when it is imported.

I copied the docs from here: What is __init__.py for?