ModuleNotFoundError: No module named 'win32api' right after I install channels

坚强是说给别人听的谎言 提交于 2019-12-10 10:25:41

问题


I am buidling a chat app with WebSockets and django channels. I run 'pip install channels' it gets installed successfully. Then I install 'asgi_redis'. That too gets installed. Now when I try to import channels.asgi it gives me error. Also suddenly my manage.py shell stops working. In other django projects it works fine.

Error when I try to access shell:

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'

Everything before installing channels seems to be working fine. settings.py:

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',
    },
}

pip freeze:

C:\Users\gdhameeja\Desktop\chatapp\chat>pip freeze
asgi-redis==1.4.3
asgiref==1.1.2
attrs==17.2.0
autobahn==17.9.3
Automat==0.6.0
channels==1.1.8
constantly==15.1.0
daphne==1.3.0
django==1.11.6
hyperlink==17.3.1
incremental==17.5.0
msgpack-python==0.4.8
pytz==2017.2
redis==2.10.6
six==1.11.0
Twisted==17.9.0
txaio==2.8.2
virtualenv==15.1.0
websocket-client==0.44.0
zope.interface==4.4.3

回答1:


https://github.com/django/channels/issues/498 Refer this post. After you get that error, manually install pypiwin32 package.

pip install pypiwin32

Even though your ide won't recognise channels to import from, ignore it and runserver. It'll work.



来源:https://stackoverflow.com/questions/47019751/modulenotfounderror-no-module-named-win32api-right-after-i-install-channels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!