python - 为什么在将 django_celery_beat 安装到我的虚拟环境并将其放入 INSTALLED_APPS 后出现“没有名为 'django_celery_beat' 的模块”?
问题描述
我正在开发一个 Django 项目,需要定期运行 cron 任务来检查并删除所有过时的文件。我用 django_extensions 和 crontab 尝试了同样的方法,但我一直收到同样的错误。在 settings.py 中,我有:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Data_Science_Web_App',
'django_celery_beat',
]
在我的 INSTALLED_APPS 部分。'Data_Science_Web_App' 是我的应用程序的名称。当我使用 pip3 install django_celery_beat 时,它运行良好。但是,当我尝试迁移更改时,我收到以下消息:
(djangoenv) Daeyongs-Air:Data_Science_Project daeyong$ python3 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-
packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File
"/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_celery_beat'
当我使用 pip freeze 检查时,很明显 django_celery_beat 在那里:
(djangoenv) Daeyongs-Air:Data_Science_Project daeyong$ pip freeze
amqp==5.0.2
asgiref==3.2.10
billiard==3.6.3.0
celery==5.0.5
certifi==2020.6.20
cffi==1.14.2
click==7.1.2
click-didyoumean==0.0.3
click-plugins==1.1.1
click-repl==0.1.6
cycler==0.10.0
Django==3.1.4
django-braces==1.14.0
django-celery-beat==2.1.0
django-common-helpers==0.9.2
django-cron==0.5.1
django-crontab==0.7.1
django-debug-toolbar==2.2
django-timezone-field==4.1.1
... 而这样的例子不胜枚举。
有人可以帮我发现这背后的问题吗?谢谢!
解决方案
我也遇到了这个。即使没有解决这个问题,我发现它应该是版本或包冲突。我试过但没有找到它们的兼容版本(django celery celery-beat-beat,也许等)
然后我从 INSTALLED_APPS 中丢弃“django_celery_beat”。无论如何,它有效。
如果您有更好的解决方案,请告诉我们。
推荐阅读
- sql - SQL Server COUNT 多个表返回错误结果
- encryption - 使用 tiny-AES-c 进行加密无线链路
- bash - 获取主机名的一部分并在 bash 中的一行中替换一些字符
- javascript - 当我尝试保存在 MongoDB 中时,.then 未定义
- angular - 如何在同一个组件Angular4中选择和显示PDF和图像文件
- sql - 制作外键并将它们转换为一个复合主键
- amazon-dynamodb - 未能在 DynamoDB 中设置 LIST 值
- python - 通过 if 语句为每行分配标签
- envoyproxy - Envoy Sidecar 能否使用 HTTP/HTTPS 代理处理出口流量
- mysql - (MySQL)无法更新存储函数/触发器中的表“PARTS”,因为它已被调用此存储函数/触发器的语句使用