Skip to main content
 首页 » 编程设计

python之在带有python2.6的windows7上使用python dragonfly的问题

2025年05月04日32www_RR

我正在玩 python 中的 Dragonfly 库。我在 Windows7 + python2.6 上工作。但是,当我尝试运行演示代码时(这是来自 Dragonfly 的示例)

from dragonfly.all import Grammar, CompoundRule 
 
# Voice command rule combining spoken form and recognition processing. 
class ExampleRule(CompoundRule): 
    spec = "do something computer"                  # Spoken form of command. 
    def _process_recognition(self, node, extras):   # Callback when command is spoken. 
        print "Voice command spoken." 
 
# Create a grammar which contains and loads the command rule. 
grammar = Grammar("example grammar")                # Create a grammar to contain the command rule. 
grammar.add_rule(ExampleRule())                     # Add the command rule to the grammar. 
grammar.load()                                      # Load the grammar. 

我收到以下错误:

Traceback (most recent call last): 
  File "test.py", line 2, in <module> 
    from dragonfly.all import Grammar, CompoundRule 
ImportError: No module named all 

我该如何解决?

请您参考如下方法:

摆脱.all。这个例子似乎已经过时了。它应该看起来像这样:

from dragonfly import Grammar, CompoundRule