Django——ModuleNotFoundError: No module named 'asgiref.sync'

Django+channels运行时报错

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f267151a840>
Traceback (most recent call last):
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/channels/apps.py", line 20, in ready
    monkeypatch_django()
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/channels/hacks.py", line 10, in monkeypatch_django
    from .management.commands.runserver import Command as RunserverCommand
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/channels/management/commands/runserver.py", line 11, in <module>
    from channels.routing import get_default_application
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/channels/routing.py", line 9, in <module>
    from channels.http import AsgiHandler
  File "/root/ENVS/dj11.7/lib/python3.7/site-packages/channels/http.py", line 16, in <module>
    from asgiref.sync import async_to_sync, sync_to_async
ModuleNotFoundError: No module named 'asgiref.sync'

解决:

pip install asgiref==2.1.1

应该是默认的asgiref版本不对,需要手动指定版本

posted @ 2018-12-01 11:01  YanceDev  阅读(2956)  评论(0编辑  收藏  举报