I am trying to setup a simple celery project. As per the official documentation, the layout is as follow:
clemux@melody ~/dev/debian/debsources/debsources
% find new_updater -name "*.py"
new_updater/tasks.py
new_updater/updater.py
new_updater/__init__.py
new_updater/celery.py
In celery.py, I import celery.Celery this way:
from __future__ import absolute_import
from celery import Celery
In IPython, I can import new_updater.celery without problems:
In [2]: from debsources.new_updater import celery
In [3]: celery?
Type: module
String form: <module 'debsources.new_updater.celery' from '/home/clemux/dev/debian/debsources/debsources/new_updater/celery.pyc'>
However, when trying to run new_updater.updater, I run into the following error:
clemux@melody ~/dev/debian/debsources
% python debsources/new_updater/updater.py
Traceback (most recent call last):
File "debsources/new_updater/updater.py", line 6, in <module>
from debsources.new_updater.tasks import print_package
File "/home/clemux/dev/debian/debsources/debsources/new_updater/tasks.py", line 3, in <module>
from debsources.new_updater.celery import app
File "/home/clemux/dev/debian/debsources/debsources/new_updater/celery.py", line 3, in <module>
from celery import Celery
File "/home/clemux/dev/debian/debsources/debsources/new_updater/celery.py", line 3, in <module>
from celery import Celery
ImportError: cannot import name Celery
What could be going on here?
I know I could simply rename celery.py to, e.g. celery_config.py (this is the standard answer to this kind of question on SO), but I'd prefer actually fixing this and not stray away from celery's official documentation.
EDIT: I printed out sys.path
in new_updater/updater.py, here's the result:
['/home/clemux/dev/debian/debsources/debsources/new_updater',
'/home/clemux/dev/debian/debsources',
'/home/clemux/.virtualenvs/debsources/lib/python2.7',
<snip>
Deleting sys.path[0]
before the other import 'solves' the issue, but I don't understand why that is in the path. How I got that:
mkvirtualenv test
python setup.py develop
at the root of my project
EDIT2: it's the same outside a virtualenv, with celery installed from debian, and my PYTHONPATH
set this way:
export PYTHONPATH=/usr/lib/python2.7/dist-packages:~/dev/debian/debsources