1

I would like to note that the following error only occurs when ran through a celery worker. with the following command in the terminal:

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 <module>
    from models.StoreConfig import StoreConfig
  File "/home/nick/mpcrawler2/models/StoreConfig.py", line 3, in <module>
    from enums.MpStores import MpStore
ImportError: No module named enums.MpStores

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

enum directory screenshot

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

The worker's starting point looks like this:

from celery import Celery

app = Celery('tasks', broker='*some ampq address here*')

The __init__.py file is empty. The enum files look like this:

from enum import Enum

# noinspection SpellCheckingInspection
class MpStore(Enum):
    somevalue = 1
    someothervalue = 2
    etc = 3

As I'm using Python 2.7 I'm using enum34 that was installed using pip.

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

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
Nick Kobishev
  • 157
  • 4
  • 13

1 Answers1

0

Well it seems like some sort of work around but following the advice in this answer: How to accomplish relative import in python

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

I would love to hear of a better way though...

Community
  • 1
  • 1
Nick Kobishev
  • 157
  • 4
  • 13