Skip to main content
 首页 » 编程设计

python之名称错误 : name 'ABNF' is not defined

2025年05月04日19zhenyulu

我在创建新的 Pebble 项目时遇到此错误

shatekar-mbp:workspace SagarHatekar$ pebble new-project hello-world 
[DEBUG   ] [Analytics] header: {'User-Agent': 'Pebble SDK/2.0.0 (Darwin-13.0.0-x86_64-i386-64bit-python-2.7.3)'}, data: {'ck': '2.7.3', 'cn': 'Darwin-13.0.0-x86_64-i386-64bit', 'cid': 'ac9248aa-9366-4714-a965-0d2a4903349e', 'tid': 'UA-30638158-7', 't': 'event', 'v': 1, 'cs': 'ac9248aa-9366-4714-a965-0d2a4903349e'} 
category: install 
action: import 
label: fail: missing import: name 'ABNF' is not defined 
value: 0 
Traceback (most recent call last): 
  File "/Users/SagarHatekar/dev/pebble/sdk/bin/../tools/pebble.py", line 20, in  
    from pebble.PblBuildCommand     import (PblBuildCommand, 
  File "/Users/SagarHatekar/dev/pebble/sdk/tools/pebble/PblBuildCommand.py", line 12, in  
    from LibPebblesCommand import (NoCompilerException, BuildErrorException, 
  File "/Users/SagarHatekar/dev/pebble/sdk/tools/pebble/LibPebblesCommand.py", line 7, in  
    import pebble as libpebble 
  File "/Users/SagarHatekar/dev/pebble/sdk/tools/pebble/pebble.py", line 21, in  
    import WebSocketPebble 
  File "/Users/SagarHatekar/dev/pebble/sdk/tools/pebble/WebSocketPebble.py", line 21, in  
    class WebSocketPebble(WebSocket): 
  File "/Users/SagarHatekar/dev/pebble/sdk/tools/pebble/WebSocketPebble.py", line 25, in WebSocketPebble 
    def write(self, payload, opcode = ABNF.OPCODE_BINARY, ws_cmd = WS_CMD_PHONE_TO_WATCH): 
NameError: name 'ABNF' is not defined

感谢任何帮助。

请您参考如下方法:

问题出在您的 websocket 和 websocket-client 上。

卸载websocket和websocket-client,然后使用pip requirements.txt重新安装

pip uninstall websocket websocket-client 
pip install -r PebbleSDK-2.0-BETA2/requirements.txt