为什么我在安装django_celery_beat到我的虚拟环境并将其放入INSTALLED_APPS后得到“No module named 'django_celery_beat'"?

g2ieeal7  于 2023-08-08  发布在  Go
关注(0)|答案(5)|浏览(208)

我正在做一个Django项目,需要定期运行cron任务来检查并删除所有过时的文件。我用django_extensions和crontab尝试了同样的方法,但我总是得到同样的错误。在www.example.com中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


...还有很多
有人能帮我找出这背后的问题吗?谢谢你,谢谢

wyyhbhjk

wyyhbhjk1#

我也遇到了这个。虽然还没有解决这个问题,我发现这应该是一个版本或包冲突。我试过,但没有找到兼容的版本(django celery celery beat beat,也许等等)。
然后我从INSTALLED_APPS中丢弃'django_celery_beat'。不管怎么说,它起作用了。
如果您有更好的解决方案,请告诉我们。

gt0wga4j

gt0wga4j2#

对我来说,问题是Python版本:django_celery_beat安装在python3.9 site-packages上,pip使用python3.8 site-packages。
尝试:

python -m pip install django-celery-beat

字符串
然后再进行以下操作:

INSTALLED_APPS = [
....,
'django_celery_beat',
]


然后迁移:

python manage.py makemigrations
python manage.py migrate

scyqe7ek

scyqe7ek3#

在INSTALLED_APPS中,django_celery_beat必须在Data_Science_Web_App之前

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_celery_beat',
    'Data_Science_Web_App',
]

字符串

z4iuyo4d

z4iuyo4d4#

对我来说,一个小的pip安装做到了。
运行这个:

pip install django-celery-beat

字符串

x8goxv8g

x8goxv8g5#

我也有这个问题,但后来我发现我在INSTALLED_APPS中添加“django_celery_beat”后没有加逗号

相关问题