【发布时间】:2018-04-11 16:45:38
【问题描述】:
我正在使用 WebSockets 和 django 频道构建一个聊天应用程序。 我运行“pip install channels”,它安装成功。然后我安装'asgi_redis'。那也被安装了。现在,当我尝试导入 channels.asgi 时,它给了我错误。我的 manage.py shell 也突然停止工作。在其他 django 项目中它工作正常。
当我尝试访问 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'
安装频道之前的一切似乎都运行良好。 设置.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',
},
}
点冻结:
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
【问题讨论】:
-
可能答案在这里:stackoverflow.com/questions/21343774/… 并且没有名为 xxx 的模块意味着您的 python 路径中没有它。
-
在发布问题之前仔细阅读。不过还是谢谢你的参考。我安装频道后它没有检测到模块是怎么回事?在这样做之前,相同的模块工作得很好
-
你在使用 virtualenv 吗?
-
虚拟环境。我之前使用的是 virtualenv,我得到了同样的错误。所以我删除了virtualenv并在没有virtualenv的情况下再次构建了项目。安装频道后两种情况相同的错误
-
好的,请在帖子中包含您的
pip freeze结果。
标签: django websocket django-channels