ModuleNotFoundError: 没有使用 celery 和 rabbitmq 的名为 'django.config' 的模块
Posted
技术标签:
【中文标题】ModuleNotFoundError: 没有使用 celery 和 rabbitmq 的名为 \'django.config\' 的模块【英文标题】:ModuleNotFoundError: No module named 'django.config' using celery and rabbitmqModuleNotFoundError: 没有使用 celery 和 rabbitmq 的名为 'django.config' 的模块 【发布时间】:2021-12-06 13:53:38 【问题描述】:运行以下命令后出现此错误:
C:\Users\callu\project_name>celery -A project_name worker -l info
我想知道这是否与我没有在虚拟环境中创建我的 django 项目但我找不到任何关于这个问题的事实有关。如果是因为它位于虚拟环境之外,我不确定如何在不重新启动项目的情况下解决它(在 PyCharm 中迁移到 venv 是否容易?)
我在这里运行我的 django 服务器和上面的 celery 命令:
C:\Users\callu\project_name>
我在另一个位置(不是 venv)运行启动我的 RabbitMQ 服务器,但不认为这是问题
完整追溯:
Traceback (most recent call last):
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\cached_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:\users\callu\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\callu\AppData\Local\Programs\Python\Python37-32\Scripts\celery.exe\__main__.py", line 7, in <module>
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\__main__.py", line 15, in main
sys.exit(_main())
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\bin\celery.py", line 213, in main
return celery(auto_envvar_prefix="CELERY")
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1135, in invoke
sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 641, in make_context
self.parse_args(ctx, args)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 940, in parse_args
value, args = param.handle_parse_result(ctx, opts, args)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 1477, in handle_parse_result
self.callback, ctx, self, value)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\click\core.py", line 96, in invoke_param_callback
return callback(ctx, param, value)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\bin\worker.py", line 156, in <lambda>
value: value or ctx.obj.app.conf.worker_state_db,
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\utils\collections.py", line 111, in __getattr__
return self[k]
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\utils\collections.py", line 391, in __getitem__
return getitem(k)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\utils\collections.py", line 249, in __getitem__
return mapping[_key]
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\collections\__init__.py", line 1021, in __getitem__
if key in self.data:
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\kombu\utils\objects.py", line 29, in __get__
return super().__get__(instance, owner)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\cached_property.py", line 74, in __get__
return obj_dict.setdefault(name, self.func(obj))
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\base.py", line 138, in data
return self.callback()
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\base.py", line 946, in _finalize_pending_conf
conf = self._conf = self._load_config()
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\app\base.py", line 956, in _load_config
self.loader.config_from_object(self._config_source)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\loaders\base.py", line 123, in config_from_object
obj = self._smart_import(obj, imp=self.import_from_cwd)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\loaders\base.py", line 136, in _smart_import
return symbol_by_name(path, imp=imp)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\kombu\utils\imports.py", line 56, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\loaders\base.py", line 95, in import_from_cwd
package=package,
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\utils\imports.py", line 100, in import_from_cwd
return imp(module, package=package)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\site-packages\celery\loaders\base.py", line 89, in import_module
return importlib.import_module(module, package=package)
File "c:\users\callu\appdata\local\programs\python\python37-32\lib\importlib\__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'
【问题讨论】:
django.config
来自哪里? (如果你错过了,那不是最初的例外。)
啊,我没有意识到这不是第一个异常,遗憾的是,该异常不是很具有描述性,cached_property.py
文件中的字典出错? django.cofig 在我的celery.py
文件中app.config_from_object('django.config:settings', namespace='CELERY')
。至少我认为它是从那里来的。
也许你的意思是'django.conf:settings'
?
是的!如此简单,不敢相信我一直错过,感谢您的帮助
你能用cached_property
重现异常吗? Scripts\celery.exe\__main__.py", line 7
是什么?
【参考方案1】:
听起来您在某个地方(在您的应用程序/celery.py
,如果使用标准布局)有如下一行:
app.config_from_object('django.config:settings', namespace='CELERY')
app
是你的 Celery 应用对象。
但你需要的是:
app.config_from_object('django.conf:settings', namespace='CELERY')
注意:您的 django 配置模块是 django.conf
而不是 django.config
。
【讨论】:
以上是关于ModuleNotFoundError: 没有使用 celery 和 rabbitmq 的名为 'django.config' 的模块的主要内容,如果未能解决你的问题,请参考以下文章
ModuleNotFoundError:使用python 3的python中没有名为“Tkinter”的模块[重复]
ModuleNotFoundError:没有名为“paypal”的模块
ModuleNotFoundError: 没有使用 celery 和 rabbitmq 的名为 'django.config' 的模块
ModuleNotFoundError:没有名为“misaka”的模块