2013-03-22 76 views
0

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

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" 

回答

0

运行如果我没有理解清楚的命令。你有你的脚本和一些脚本来调用你的脚本来显示它正在工作吗?

您错过了这一点。 您的脚本假设为最终产品。

如果要测试功能,请在开发版本中进行。
如果你想测试exe文件,可以通过另一个(分离的)测试脚本来完成。

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

我建议你建立主要的入口点脚本(如果你需要参数),因为它是要完成的。 并让其他脚本运行你的脚本。

或者创建一个模块并使用该模块构建脚本。 然后建立这个示例脚本exe文件使用该模块,并显示它的工作原理

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

+0

我的主脚本dragonfly-main.py正在将目录中的每个示例文件作为模块加载。它可以在IDE中做到这一点,但是在使用pyinstaller时,无论出于何种原因,它都不会获得我的示例文件。蜻蜓主要不知道其他模块是什么。 – tiggles 2013-03-23 02:58:13

+0

示例文件是示例文件而非模块。创建你分离的项目,将蜻蜓导入它。如果您需要示例文件中的代码 - 将其复制并过滤到您的项目中,您需要多少。 – 2013-03-23 09:57:04

+0

你说得对,我试图做的一切倒退哈哈。我是python的新手。谢谢你的帮助。 – tiggles 2013-03-24 16:20:21

相关问题