简体   繁体   English

Django ModuleNotFoundError:没有名为“asgiref”的模块

[英]Django ModuleNotFoundError: No module named 'asgiref'

I have a Django service we are trying to schedule in conjunction with the main application that runs periodically to send automated emails via a batch script.我有一个 Django 服务,我们试图与定期运行的主应用程序一起安排,以通过批处理脚本发送自动电子邮件。

The Django application itself starts up fine, but when I try running the batch script, I get the following traceback: Django 应用程序本身启动良好,但是当我尝试运行批处理脚本时,我得到以下回溯:

Traceback (most recent call last):                                                                                        
File "C:\Program Files\compuweather\compuweather\webapp\management\commands\send_all_clients.py", 
line 2, in <module>     from django.core.management.base import BaseCommand                                                                   
File "C:\ProgramData\Anaconda3\lib\site-packages\django-3.2- 
py3.8.egg\django\core\management\__init__.py", line 13, in <module>                                                                                                                   
from django.apps import apps                                                                                          
File "C:\ProgramData\Anaconda3\lib\site-packages\django-3.2-py3.8.egg\django\apps\__init__.py", line 
1, in <module>       from .config import AppConfig                                                                                         
File "C:\ProgramData\Anaconda3\lib\site-packages\django-3.2-py3.8.egg\django\apps\config.py", line 7, 
in <module>         from django.utils.deprecation import RemovedInDjango41Warning                                                         
File "C:\ProgramData\Anaconda3\lib\site-packages\django-3.2-py3.8.egg\django\utils\deprecation.py", 
line 5, in <module>                                                                                                                           
from asgiref.sync import sync_to_async                                                                              
ModuleNotFoundError: No module named asgiref

I find that odd considering I have the batch file set to run from an anaconda environment that has Asgiref installed.考虑到我将批处理文件设置为从安装了 Asgiref 的 anaconda 环境运行,我觉得这很奇怪。 I can verify this with pip freeze.我可以通过 pip 冻结来验证这一点。 Here are the versions of the packages I'm using:以下是我正在使用的软件包版本:

asgiref==3.3.1 asgiref==3.3.1
Django==3.1.6 Django==3.1.6

I saw a similar issue here , that was due to the Django and asgiref packages being outdated.我在这里看到了类似的问题,这是由于 Django 和 asgiref 包已过时。 I've tried updating both asgiref and Django to the latest versions (those listed), but that also didn't help.我已经尝试将 asgiref 和 Django 更新到最新版本(列出的那些),但这也没有帮助。

My best guess after looking through the traceback is either something is trying to use a deprecated package (hence the use of deprecation.py) or a path needs to be appended somewhere.查看回溯后,我最好的猜测是尝试使用已弃用的 package(因此使用 deprecation.py)或需要在某处附加路径。 If the former, is there an alternative I should be using?如果是前者,我应该使用其他替代方法吗?

For reference, here is the batch file I am trying to use:作为参考,这是我尝试使用的批处理文件:

call C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3 
call activate test
"C:\ProgramData\Anaconda3\Python.exe" "C:\Program Files\compuweather\compuweather\webapp\management\commands\send_all_clients.py"

You can use manage.py to run your custom management command from your batch and have access to your project environment:您可以使用manage.py从批处理中运行自定义管理命令并访问您的项目环境:

python C:\Program Files\compuweather\compuweather\manage.py send_all_clients

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM