Forums

cant properly import module

error:

09:11 ~/rssDj/rssReader $ python rssReader.py
Traceback (most recent call last):
  File "rssReader.py", line 21, in <module>
    from models import FreqWord, WordIds, PrimaryData
  File "/home/kernie_xvid/rssDj/rssDjApp/models.py", line 3, in <module>
    class FreqWord(models.Model):
  File "/usr/local/lib/python2.7/site-packages/Django-1.3.3-py2.7.egg/django/db/models/base.py", line 52, in __new__
    kwargs = {"app_label": model_module.__name__.split('.')[-2]}
IndexError: list index out of range

code of script:

...some imports...
sys.path.append('/home/kernie_xvid/rssDj')
sys.path.append('/home/kernie_xvid/rssDj/rssDjApp')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from models import FreqWord, WordIds, PrimaryData

code of models:

from django.db import models

class FreqWord(models.Model):
    word = models.CharField(max_length=64)
    freq = models.IntegerField()
    wordId = models.CharField(max_length=64)
    checkDate = models.DateTimeField()

et c.

Hi kernie_xvid,

That's an unusual one! Could you try only adding /home/kernie_xvid/rssDj and then doing your import line like this:

from rssDjApp.models import FreqWord, WordIds, PrimaryData

In settings.py how have you added rssDjApp? Did you add it as 'rssDjApp' or 'rssDj.rssDjApp'? If the first suggestion doesn't do anything you could try changing that. It seems like django is confused by your directory structure in some way.

solved, thankyou; in settings.py there was 'rssDj.rssDjApp', now its 'rssDjApp';