Search code examples
pythondjangodjango-modelsmoduleimporterror

ImportError: No module named lop.models


I know there are a lot of questions related to this, but those answers don't seem to work in my situation. I'm new to Django (I've done the tutorial), but I'm fixing someone else's code who I can no longer contact.

I'm running django 1.5 on Debian with python 2.7. I received this error.

File "views-full.py", line 1, in <module>
    from lop.models import File, V1, V2
ImportError: No module named lop.models.

views-full.py:

from lop.models import File, V1, V2
...

My tree is this (to save time, my views-full.py is under lop):

Main
├── Main
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── manage.py
├── lop
│   ├── admin.py
│   ├── admin.pyc
│   ├── forms.py
│   ├── forms.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   │   ├── 0001_migrate.py
│   │   ├── 0001_migrate.pyc
│   │   ├── 0002_migrate.py
│   │   ├── 0002_migrate.pyc
│   │   ├── 0003_auto__add_category.py
│   │   ├── 0003_auto__add_category.pyc
│   │   ├── 0004_auto__add_field_script_category.py
│   │   ├── 0004_auto__add_field_script_category.pyc
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── views
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── viewsb.py
│   │   ├── viewsb.pyc
│   │   └── viewsb.py.save
│   ├── views-full.py
│   ├── views.pyc
│   ├── views.py.save
│   └── views-test.py
├── scripts [39 entries exceeds filelimit, not opening dir]
├── sqlite3.db
├── static [29 entries exceeds filelimit, not opening dir]
├── templates
│   ├── entry2-full.html
│   ├── entry2.html
│   ├── entry3-full.html
│   ├── entry3.html
│   ├── entry.html
│   ├── index.html
│   ├── index.html.old
│   ├── scriptlist.html
│   └── testData.html
└── user-dirs [109 entries exceeds filelimit, not opening dir] 

As you see, both my __init__.py and models.py are in the same folder (which I know that them not being there was the problem in other cases).

settings.py:

 ...     
 INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    # 'django.contrib.admindocs',
    'lop',
    'south',
)
...

I feel like I'm making some rookie mistake, but I can't figure it out.


Solution

  • So I figured out the problem which was from a fault on my part.

    For the longest time, I thought that to test for any compilation errors (syntax), I would run "python < filename > migrate" or "python < filename > makemigrations" on the shell. My belief was that all changes needed to be migrated and not just ones in the database. I get errors messages when syntax mistake including this one and it has worked in other cases before. Someone eventually pointed out to me that is NOT how you test it and running "python manage.py runserver 0.0.0.0:8000" would point out any errors in the code in your local machine. I got no error messages for my specific file after that.

    Gabriel L'Heureux, I still appreciated your help (I would give you a point up for it but I don't have enough points to do so) so you have my thanks.