ModuleNotFoundError:没有名为' win32api'我安装频道后

时间:2017-10-30 16:12:26

标签: django websocket django-channels

我正在使用WebSockets和django频道建立聊天应用。 我运行了'pip install channels'它安装成功。然后我安装' asgi_redis'。那也被安装了。现在,当我尝试导入channels.asgi时,它给了我错误。突然我的manage.py shell停止工作。在其他django项目中,它可以正常工作。

尝试访问shell时出错:

tld

安装频道之前的一切似乎都运转正常。 settings.py:

C:\Users\gdhameeja\Desktop\chatapp\chat>manage.py shell
Traceback (most recent call last):
  File "C:\Users\gdhameeja\Desktop\chatapp\chat\manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\core\management\__init__.py", line 338, in execute
    django.setup()
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\django-1.11.6-py3.6.egg\django\apps\registry.py", line 116, in populate
    app_config.ready()
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\apps.py", line 17, in ready
    monkeypatch_django()
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\hacks.py", line 10, in monkeypatch_django
    from .management.commands.runserver import Command as RunserverCommand
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\channels\management\commands\runserver.py", line 5, in <module>
    from daphne.server import Server, build_endpoint_description_strings
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\daphne\server.py", line 9, in <module>
    from twisted.internet.endpoints import serverFromString
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\endpoints.py", line 41, in <module>
    from twisted.internet.stdio import StandardIO, PipeAddress
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\stdio.py", line 30, in <module>
    from twisted.internet import _win32stdio
  File "C:\Users\gdhameeja\AppData\Local\Programs\Python\Python36\lib\site-packages\twisted\internet\_win32stdio.py", line 9, in <module>
    import win32api
ModuleNotFoundError: No module named 'win32api'

pip freeze:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'chat',
    'channels',]
CHANNEL_LAYERS = {
    'default': {
        'BACKEND' : 'asgi_redis.RedisChannelLayer',
        'CONFIG':{
            'hosts': [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
        },
        'ROUTING' : 'chat.routing.channel_routing',
    },
}

1 个答案:

答案 0 :(得分:2)

https://github.com/django/channels/issues/498 参考这篇文章。收到该错误后,请手动安装pypiwin32软件包。

SELECT
    f.f_name
    ,s.s_name
FROM faculty f
JOIN subject s ON
    f.f_code=s.facultycode
GROUP BY
    f.f_name
    ,s.s_name;

即使您的ide无法识别要导入的频道,也请忽略它和runserver。它会工作。