0

I have a django application I've added celery. In django application I have a package named 'parser', 'api'. I configured the celery as I followed the following tutorial: First steps with Django. In parser package I have 'models.py'. Do you 'task.py' package 'api'. When I try to do 'from parser import models' in api package . I get the following error: No module named models

I looked and found that the following import file: lib/python2.7/lib-dynload/parser.x86_64-linux-gnu.so

webapp/               
  manage.py         
  api/       
    __init__.py
    models.py
    views.py
    tasks.py
    ...
  parser/       
    __init__.py
    models.py
    views.py
    ...
  settings/
    __init__.py
    base.py
    celery.py
    dev.py
    live.py
    local.py
    urls.py
    wsgi.py

In case I need 'models.py' of parser package. Command you use to start the celery is following: celery -A settings worker --loglevel=info. When I run celery in manage.py then take the right file: python manage.py celery -A settings worker --loglevel=info

api/task.py

from __future__ import absolute_import, division, print_function, unicode_literals
import time
from celery import task
from parser.models import FileUploadProcess # Error import


@task()
def test_task(param1):
    print("Test task called. Param: {}".format(param1))
    return 42


@task()
def parse_file(file_candidate, candidate_id):
    FileUploadProcess(candidate_id=candidate_id, is_process=True).save()
    # parse file
    time.sleep(15)
    FileUploadProcess.objects.filter(candidate_id=candidate_id).update(is_process=False)

Can somehow tell me Imports right package?

Krasimir
  • 1,806
  • 2
  • 18
  • 31

1 Answers1

0

'from parser import models'

You need to use is so:

 from parser.models import ClassName

where ClassName is name of class you want to import

or just

 import parser.models as models
Zav
  • 671
  • 3
  • 8
  • What is base directory you run from script? Looks like you import default python [parser module](https://docs.python.org/3.3/library/parser.html) instead one in your directory – Zav Oct 18 '14 at 09:47
  • May be try to rename parser into something else? – Zav Oct 18 '14 at 09:48
  • Rename the package will most likely solve the problem, but should remain as it is now. Command: `celery -A settings worker --loglevel=info` starts from webapp folder. – Krasimir Oct 18 '14 at 09:55
  • 1
    http://stackoverflow.com/questions/6031584/python-importing-from-builtin-library-when-module-with-same-name-exists may be this will help? – Zav Oct 18 '14 at 10:36