celery task unable to import ImportError of a module from inside the project
<p>I would like to note that the following error only occurs when ran through a celery worker.
with the following command in the terminal:</p>

<pre><code>celery -A MarketPlaceTasks worker --loglevel=info

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 218, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 398, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/nick/mpcrawler2/MarketPlaceTasks.py", line 65, in get_item_data
    logger, request, run_data, store_config, app_config = setup_task(payload)
  File "/home/nick/mpcrawler2/MarketPlaceTasks.py", line 33, in setup_task
    store_config = ConfigReader.read_store_config(request.Store)
  File "/home/nick/mpcrawler2/shared/ConfigReader.py", line 22, in read_store_config
    from singletons.StoreData import StoreData
  File "/home/nick/mpcrawler2/singletons/StoreData.py", line 3, in &lt;module&gt;
    from models.StoreConfig import StoreConfig
  File "/home/nick/mpcrawler2/models/StoreConfig.py", line 3, in &lt;module&gt;
    from enums.MpStores import MpStore
ImportError: No module named enums.MpStores
</code></pre>

<p>I have all my enums in a separate module.  The module looks like this, and is located inside the same directory as the project:</p>

<p><a href="http://i.stack.imgur.com/VDANU.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/VDANU.jpg" alt="enum directory screenshot"></a></p>

<p>Whenever I run the project via pycharm or terminal everything seems to work as intended.</p>

<p>The worker's starting point looks like this:</p>

<pre><code>from celery import Celery

app = Celery('tasks', broker='*some ampq address here*')
</code></pre>

<p>The <code>__init__.py</code> file is empty.  The enum files look like this:</p>

<pre><code>from enum import Enum

# noinspection SpellCheckingInspection
class MpStore(Enum):
    somevalue = 1
    someothervalue = 2
    etc = 3
</code></pre>

<p>As I'm using Python 2.7 I'm using <a href="https://pypi.python.org/pypi/enum34" rel="nofollow"><code>enum34</code></a> that was installed using pip.</p>

<p>Please let me know if there's anything else I should provide in the question.</p>

<p>Well it seems like some sort of work around but following the advice in this answer:
<a href="http://stackoverflow.com/questions/4655526/how-to-accomplish-relative-import-in-python/4656228#4656228">How to accomplish relative import in python</a></p>

<p>I moved most of the project inside a "main" module containing all of them. and then i was able to:
instead of <code>from enums.MpStore import MpStore</code><br>
I now use <code>from stuff.enums.MpStore import MpStore</code> "stuff" being the new module name.  </p>

<p>I would love to hear of a better way though...</p>

python python-2.7 enums celery celery-task