2013-03-22 50 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

相關問題