ModuleNotFoundError: No module named ‘django.config’ using celery and rabbitmq

  celery, django, python, rabbitmq, virtualenv

I’m getting this error after running the following command:

C:Userscalluproject_name>celery -A project_name worker -l info

I’m wondering if it has something to do with the fact that I’ve not created my django project in a virtual environment but I can’t find anything on the issue. If it was due to it being outside a virtual environment I’m not sure how I’d get around it without restarting the project in one (is it easy to move to a venv in PyCharm?)

I run my django server and my above celery command here:


I run start my RabbitMQ server in another location (not venv) but don’t think that’s the issue

Full Traceback:

Traceback (most recent call last):
  File "", line 70, in __get__
    return obj_dict[name]
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "", line 85, in _run_code
    exec(code, run_globals)
  File "", line 7, in <module>
  File "", line 15, in main
  File "", line 213, in main
    return celery(auto_envvar_prefix="CELERY")
  File "", line 764, in __call__
    return self.main(*args, **kwargs)
  File "", line 717, in main
    rv = self.invoke(ctx)
  File "", line 1135, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
  File "", line 641, in make_context
    self.parse_args(ctx, args)
  File "", line 940, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "", line 1477, in handle_parse_result
    self.callback, ctx, self, value)
  File "", line 96, in invoke_param_callback
    return callback(ctx, param, value)
  File "", line 156, in <lambda>
    value: value or,
  File "", line 111, in __getattr__
    return self[k]
  File "", line 391, in __getitem__
    return getitem(k)
  File "", line 249, in __getitem__
    return mapping[_key]
  File "", line 1021, in __getitem__
    if key in
  File "", line 29, in __get__
    return super().__get__(instance, owner)
  File "", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "", line 138, in data
    return self.callback()
  File "", line 946, in _finalize_pending_conf
    conf = self._conf = self._load_config()
  File "", line 956, in _load_config
  File "", line 123, in config_from_object
    obj = self._smart_import(obj, imp=self.import_from_cwd)
  File "", line 136, in _smart_import
    return symbol_by_name(path, imp=imp)
  File "", line 56, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "", line 95, in import_from_cwd
  File "", line 100, in import_from_cwd
    return imp(module, package=package)
  File "", line 89, in import_module
    return importlib.import_module(module, package=package)
  File "", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.config'

Source: Python Questions