Django Channels No module named 'asgiref.sync' 错误

Posted

技术标签:

【中文标题】Django Channels No module named \'asgiref.sync\' 错误【英文标题】:Django Channels No module named 'asgiref.sync' errorDjango Channels No module named 'asgiref.sync' 错误 【发布时间】:2019-10-08 13:41:51 【问题描述】:

我正在尝试为我的项目使用频道。我按照本教程Raspberry PI and Django Channels 开发我的项目。但是使用python3 manage.py runsever 运行服务器会给我以下错误。

root@raspberrypi:/home/pi/sensor# python3 manage.py runserver 0:8000
:0: UserWarning: You do not have a working installation of the service_identity module: 'cannot import name 'opentype''.  Please install it from <https://pypi.python.org/pypi/service_identity> and make sure all of its dependencies are satisfied.  Without the service_identity module, Twisted can perform only rudimentary TLS client hostname verification.  Many valid certificate/hostname mappings may be rejected.
:0: UserWarning: You do not have a working installation of the service_identity module: 'cannot import name 'opentype''.  Please install it from <https://pypi.python.org/pypi/service_identity> and make sure all of its dependencies are satisfied.  Without the service_identity module, Twisted can perform only rudimentary TLS client hostname verification.  Many valid certificate/hostname mappings may be rejected.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 77, in raise_last_exception
    raise _exception[0](_exception[1]).with_traceback(_exception[2])
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/usr/local/lib/python3.5/dist-packages/channels/apps.py", line 20, in ready
    monkeypatch_django()
  File "/usr/local/lib/python3.5/dist-packages/channels/hacks.py", line 10, in monkeypatch_django
    from .management.commands.runserver import Command as RunserverCommand
  File "/usr/local/lib/python3.5/dist-packages/channels/management/commands/runserver.py", line 11, in <module>
    from channels.routing import get_default_application
  File "/usr/local/lib/python3.5/dist-packages/channels/routing.py", line 9, in <module>
    from channels.http import AsgiHandler
  File "/usr/local/lib/python3.5/dist-packages/channels/http.py", line 17, in <module>
    from asgiref.sync import async_to_sync, sync_to_async
ImportError: No module named 'asgiref.sync'  

我该如何解决这个问题? 蟒蛇:3.5.3 django:2.21 频道:2.2.0 asgiref: 3.1.2

【问题讨论】:

【参考方案1】:

您的频道版本是最新的,因此请安装最新版本的 asgiref,尝试:

pip install asgiref==3.1.2

【讨论】:

以上是关于Django Channels No module named 'asgiref.sync' 错误的主要内容,如果未能解决你的问题,请参考以下文章

Django报错 No module named 'django.templates'

Django 错误之 No module named ‘MySQLdb’

Django 已安装但无法运行 - ModuleNotFoundError: No module named 'django'

django安装了pymysql还报MySQLdb module: No module named

django no module splite3的问题

Django异常 - ImportError: No module named django.core.management