I have created a small script for comparing how similar two images are. This is contained in a file called compare_image.py, which contains just one function, compare. This file is in the app directory. I am trying to import it from the models.py file using the line import compare_image, but attempting this results in the error message ModuleNotFoundError: No module named 'compare_image'.
The simplified directory structure looks like this:
myproject
└── myapp
├── __init__.py
├── admin.py
├── apps.py
├── compare_image.py
├── forms.py
├── models.py
├── tests.py
├── urls.py
└── views.py
myapp is the only app in the project. Apart from this, the webapp functions fine.
I have tried deleting and retouching the __init__.py file to no avail. I can import compare_image fine from a python shell in the myapp directory. The only imports in compare_image.py are to PIL or standard libraries, so I don't think circular imports are the culprit.
One solution would be to just put the code in models.py, but I don't want to clutter this file.
I thought since this error seems so basic there might be some standard mechanism for user-written scripts in Django, but I can't find any mention of this online.
I would be happy to provide more details about the project if it will make things clearer. Thanks in advance for any help (this error is driving me crazy!)