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:

C:Userscalluproject_name>

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 "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagescached_property.py", 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 "c:userscalluappdatalocalprogramspythonpython37-32librunpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:userscalluappdatalocalprogramspythonpython37-32librunpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:UserscalluAppDataLocalProgramsPythonPython37-32Scriptscelery.exe__main__.py", line 7, in <module>
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagescelery__main__.py", line 15, in main
    sys.exit(_main())
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagescelerybincelery.py", line 213, in main
    return celery(auto_envvar_prefix="CELERY")
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 1135, in invoke
    sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 641, in make_context
    self.parse_args(ctx, args)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 940, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 1477, in handle_parse_result
    self.callback, ctx, self, value)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesclickcore.py", line 96, in invoke_param_callback
    return callback(ctx, param, value)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagescelerybinworker.py", line 156, in <lambda>
    value: value or ctx.obj.app.conf.worker_state_db,
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryutilscollections.py", line 111, in __getattr__
    return self[k]
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryutilscollections.py", line 391, in __getitem__
    return getitem(k)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryutilscollections.py", line 249, in __getitem__
    return mapping[_key]
  File "c:userscalluappdatalocalprogramspythonpython37-32libcollections__init__.py", line 1021, in __getitem__
    if key in self.data:
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packageskombuutilsobjects.py", line 29, in __get__
    return super().__get__(instance, owner)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagescached_property.py", line 74, in __get__
    return obj_dict.setdefault(name, self.func(obj))
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryappbase.py", line 138, in data
    return self.callback()
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryappbase.py", line 946, in _finalize_pending_conf
    conf = self._conf = self._load_config()
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryappbase.py", line 956, in _load_config
    self.loader.config_from_object(self._config_source)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryloadersbase.py", line 123, in config_from_object
    obj = self._smart_import(obj, imp=self.import_from_cwd)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryloadersbase.py", line 136, in _smart_import
    return symbol_by_name(path, imp=imp)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packageskombuutilsimports.py", line 56, in symbol_by_name
    module = imp(module_name, package=package, **kwargs)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryloadersbase.py", line 95, in import_from_cwd
    package=package,
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryutilsimports.py", line 100, in import_from_cwd
    return imp(module, package=package)
  File "c:userscalluappdatalocalprogramspythonpython37-32libsite-packagesceleryloadersbase.py", line 89, in import_module
    return importlib.import_module(module, package=package)
  File "c:userscalluappdatalocalprogramspythonpython37-32libimportlib__init__.py", 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

LEAVE A COMMENT