首页 > 解决方案 > 在 windows 上使用 channels_redis

问题描述

我正在尝试遵循这个基本的 django 频道教程,我已经有了一个很好的开始。我能够成功连接到我的 websocket,并且我的消费者在收到消息时正确地回显到前端。

本教程的下一部分将重点介绍如何使用channels_redis以允许多个通道都接收相同的消息,以便不同的客户端实例可以通过 websockets 相互通信。

在教程中他们说要运行

pip3 install channels_redis

如果失败,他们不会详细说明或提供任何故障排除。

当我在我的 Windows 机器(Python 3.7 32bit)上运行此命令时,我得到以下堆栈跟踪:

Installing collected packages: hiredis, aioredis, channels-redis
  Running setup.py install for hiredis ... error
    Complete output from command C:\work_repos\WebWorkspace\PersonQueue\venv\Scr
ipts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\o_O\\App
Data\\Local\\Temp\\pip-build-vk3mqeh1\\hiredis\\setup.py';f=getattr(tokenize, 'o
pen', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile
(code, __file__, 'exec'))" install --record C:\Users\o_O\AppData\Local\Temp\pip-
dyn4y_6y-record\install-record.txt --single-version-externally-managed --compile
 --install-headers C:\work_repos\WebWorkspace\PersonQueue\venv\include\site\pyth
on3.7\hiredis:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\hiredis
    copying hiredis\version.py -> build\lib.win32-3.7\hiredis
    copying hiredis\__init__.py -> build\lib.win32-3.7\hiredis
    running build_clib
    building 'hiredis_for_hiredis_py' library
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\vendor
    creating build\temp.win32-3.7\vendor\hiredis
    C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC
\14.15.26726\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:\Pr
ogram Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26
726\include" /Tcvendor/hiredis/read.c /Fobuild\temp.win32-3.7\vendor/hiredis/rea
d.obj
    read.c
    vendor/hiredis/read.c(34): fatal error C1083: Cannot open include file: 'str
ing.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Buil
dTools\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x86\\cl.exe' failed with exi
t status 2

这似乎是一个依赖的问题hiredis。在网上搜索我发现其他人在 Windows 上使用hiredis时遇到了麻烦,但解决方案并不多。

所以我的问题是:是否可以channels_redis在 Windows 上使用该软件包?我知道 windows 显然不能成为最好的生产部署环境,但我不打算在 windows 服务器上部署。在这一点上,我只是尝试遵循一个基本教程并构建一个能够进行 websocket 通信的简单概念验证应用程序。我没有在我的开发机器上使用 Linux 的选项,所以我专门寻找基于 Windows 的解决方案。

编辑附加信息:

标签: pythonwindowsredisdjango-channelshiredis

解决方案


推荐阅读