1

我正在运行 2.7,并且正在使用 pyinstaller。我的目标是输出一个 exe 并让它运行我的其他类文件。我还使用https://code.google.com/p/dragonfly/作为语音识别框架。我在 Dragonfly->examples->text.py 下的示例方向创建了另一个文件。如果我用我的 IDE 运行https://code.google.com/p/dragonfly/source/browse/trunk/dragonfly/examples/dragonfly-main.py?spec=svn79&r=79我可以说语音命令,它会理解我创建的以下文件和蜻蜓示例中的其他示例文件。

    from dragonfly.all import Grammar, CompoundRule, Text, Dictation
import sys
sys.path.append('action.py')
import action

# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    print "This works"
    spec = "do something computer"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print "Voice command spoken."

class AnotherRule(CompoundRule):
    spec = "Hi there"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print "Well, hello"




# 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.add_rule(AnotherRule())                     # Add the command rule to the grammar.
grammar.load()           

                       # Load the grammar.

我在控制台中注意到它会输出

UNKNOWN: valid paths: ['C:\\Users\\user\\workspace\\dragonfly\\dragonfly-0.6.5\\dragonfly\\examples\\action.py',etc..etc...

在我使用 pyinstaller 之后,该行的输出是

UNKNOWN: valid paths: []

所以它没有加载示例,因为它找不到它们。我如何告诉 pyinstaller 在创建 exe 时也加载示例文件?如果它确实加载了文件,我如何确保我的 exe 知道文件在哪里?

我为 pyinstaller 运行的命令

C:\Python27\pyinstaller-2.0>python pyinstaller.py -p-paths="C:\Users\user\worksp
ace\dragonfly\dragonfly-0.6.5\dragonfly\examples\test.py" "C:\Users\user\workspa
ce\dragonfly\dragonfly-0.6.5\dragonfly\examples\dragonfly-main.py"
4

1 回答 1

0

如果我理解清楚。你有你的脚本和一些示例脚本,它们调用你的脚本来表明它正在工作?

你错过了重点。您的脚本应该是最终产品。

如果您想测试功能,请在开发版本中进行。
如果您想测试 exe 文件,请通过另一个(单独的)测试脚本执行此操作。

其他:
脚本和模块是完全不同的东西。
您正在尝试将脚本作为模块导入并在示例脚本中使用它。

我建议您构建脚本的主要入口点(如果需要,可以使用参数),因为它应该完成。并制作其他运行您的脚本的示例脚本。

或者制作一个模块并构建使用该模块的脚本。然后将此示例脚本构建为使用该模块并显示其工作的 exe 文件

PyInstaller 可以一次编译一个脚本。不需要强迫它做不寻常的事情。

于 2013-03-22T23:28:00.123 回答