Domanda

I came across a file in our project, called - wait for it - celery.py. Yes, and celery.py imports from the installed celery module (see http://www.celeryproject.org/) which is not an issue because the project's celery.py uses

from __future__ import absolute_import     

before importing from the installed celery module. Now, the problem comes from djcelery (django-celery) which also would like to import from celery (the installed one, not the project celery.py). This is where the clash comes because djcelery encounters the project's celery.py before it encounters the installed celery. How can I resolve this?

È stato utile?

Soluzione

The easiest and most sane way to do it is to refactor you project and change the name of the file.

There are probably some way strange way around this, but I would hardly consider that worth it, as it would most likely complicate your code, and make it prone to errors.

Altri suggerimenti

As @Chirila Alexandru said, just rename the module.

You could also:

  • add from __future__ import absolute_import at the top of the file that imports celery (to import your celery.py instead, you could use from project.your_app import celery)
  • use explicit relative import, to import your celery.py: from . import celery
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top