我正在運行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"
我的主腳本dragonfly-main.py正在將目錄中的每個示例文件作爲模塊加載。它可以在IDE中做到這一點,但是在使用pyinstaller時,無論出於何種原因,它都不會獲得我的示例文件。蜻蜓主要不知道其他模塊是什麼。 – tiggles 2013-03-23 02:58:13
示例文件是示例文件而非模塊。創建你分離的項目,將蜻蜓導入它。如果您需要示例文件中的代碼 - 將其複製並過濾到您的項目中,您需要多少。 – 2013-03-23 09:57:04
你說得對,我試圖做的一切倒退哈哈。我是python的新手。謝謝你的幫助。 – tiggles 2013-03-24 16:20:21