首页 > 解决方案 > AttributeError:模块“websocket”没有属性“WebSocketApp”

问题描述

相关代码片段:

点安装 websocket 客户端

导入 websocket

def on_open(ws): blahblah

def on_close(ws): blahblahblah

def on_message(ws,message): blahblahblah

ws = websocket.WebSocketApp(SOCKET,on_open=on_open,on_close=on_close,on_message=on_message)

ws.run_forever()

我收到错误 AttributeError: module 'websocket' has no attribute 'WebSocketApp' on j upyter notebook这很奇怪,因为我在Google Colab上运行完全相同的代码,但我没有收到任何错误。

我什么都试过了!!我尝试按照此处的建议进行操作:AttributeError: module 'websocket' has no attribute 'WebSocketApp' pip

我也试过这个:AttributeError: 'module' object has no attribute 'WebSocketApp'

我试图在我的文件中搞砸,但无论我做什么,我都会继续收到这个错误......

我的 python 版本是 3.8.3 顺便说一句。有没有人知道这里有什么问题?

标签: pythonwebsocket

解决方案


尝试从打开的终端或命令提示符运行,我在尝试使用 python 脚本包在 ATOM 中运行代码时遇到了同样的问题。我认为与安装多个版本的 Python 有关。


推荐阅读