AttributeError: module ‘websocket’ has no attribute 'enableTrace’
環境
windows 11
Python 3.10websocket 0.2.1
websocket-client 1.8.0
websockets 11.0.3
rel 0.4.9.19
詳情
一開始是通過pip直接安裝 websocket-client
和 websocket
庫。
pip install websocket websocket-client
然后運行帶有websocket.enableTrace(True)
的代碼時彈出這個錯誤。
問題原因是這樣安裝會造成 websocket-client 和 websocket 庫沖突。websocket中沒有enableTrace
模塊,還會影響websocket-client。
需要分開安裝,而且需要最后
安裝websocket-client庫。
解決方法
卸載 websocket-client 庫,然后再重新安裝,但要帶具體版號(可以去websocket-client · PyPI查看最新版號)。
注意:如果不用 websocket ,是不用安裝它的。
這個時候如果之前安裝了websocket庫,不用卸載。
# 1 卸載
pip uninstall websocket-client# 2 重新安裝
pip install websocket-client==1.8.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
參考
AttributeError: module ‘websocket‘ has no attribute ‘enableTrace‘_attributeerror: module ‘websocket’ has no attribut-CSDN博客
Examples — websocket-client 1.8.0 documentation