Search code examples
pythondjangopython-2.7django-appsdjango-1.11

Django can't import app from apps' folder, ImportError


I have old project made on Django 1.11.10 and Python 2.7

Imports like below aren't working

from apps.configuration.utils import HrefModel

Traceback

 from apps.configuration.utils import HrefModel

 ImportError: No module named configuration.utils

Installed apps inside settings

 INSTALLED_APPS = [
    some django apps...

    "apps.configuration",
    "apps.nav",
    "apps.pages",

    more similar apps...
]

Project's folder structure

project_name/
├── apps
│   ├── account
│   ├── administration
│   ├── catalog
│   ├── configuration
│   │     ├── admin.py
│   │     ├── apps.py
│   │     ├── context_processors.py
│   │     ├── __init__.py
│   │     ├── lookups.py
│   │     ├── management
│   │     ├── migrations
│   │     ├── models
│   │     ├── templatetags
│   │     ├── tests.py
│   │     ├── utils
│   │     └── views.py
│   ├── content
│   ├── elastic_search
│   ├── feedback
│   ├── google_captcha
│   ├── __init__.py
│   ├── nav
│   ├── pages
│   ├── posts
│   ├── shop
├── docker-compose.yml
├── Dockerfile
├── entrypoint.sh
├── manage.py
├── requirements.txt

utils folder inside configuration app

utils/
├── bank.py
├── format.py
├── __init__.py
├── objects.py
├── pagination.py
└── slug.py

Objects.py contains the class, that I want to import


Solution

  • Changed python2.7 to python3.5 and that got me rid of the exception

    The Django documentation says

    Python compatibility
    Like Django 1.9, Django 1.10 requires Python 2.7, 3.4, or 3.5

    https://docs.djangoproject.com/en/3.1/releases/1.10/