2016-02-28 83 views
0

我寫了一個簡單的python文件,我試圖讀取文本文件並將一些日誌寫入輸出文件。使用pyinstaller我創建了一個.exe文件。但是當我執行那個.exe文件時,它會拋出以下錯誤。Pyinstaller拋出錯誤沒有這樣的文件或目錄

Traceback (most recent call last): 
    File "<string>", line 31, in <module> 
    File "<string>", line 15, in process_data 
IOError: [Errno 2] No such file or directory: 'input1.txt' 
mytest returned -1 

這是我的代碼。

import re 
import sys 
import mytest2 

def process_data(name, course): 

    tmp = sys.stdout 
    sys.stdout = open("out11.txt", 'w') 

    if re.search("^ank", name): 
     print "Yes I am here" 
    else: 
     print "No no wrong door" 

    fr = open("input1.txt", "r") 
    lines = fr.readlines() 
    fr.close() 

    print "Printing from input file.." 
    for line in lines: 
     print line.strip() 

    sys.stdout.close() 
    sys.stdout = tmp 


if __name__ == "__main__": 
    arg1 = sys.argv[1] 
    arg2 = sys.argv[2] 

    process_data(arg1, arg2) 

有人可以告訴我如何解決這個問題。我在Windows中這樣做。

我也想知道這是否可執行將在所有Windows操作系統的工作就像贏得8,8.1,10等

回答

1

要麼input1.txt是不是你有.exe文件夾中,或者.exe希望你有input1.txt打包成它 - onefile/singlefile選項在pyinstaller。

+0

它位於同一個文件夾中,我曾在pyinstaller中使用過--onefile選項 – user2550098

+0

嘗試將'input1.txt'打包到'.exe'文件或將文件路徑作爲參數傳遞 – KeyWeeUsr

+0

嗨,謝謝。它不會拋出這個錯誤。但現在我得到了不同的錯誤。 – user2550098

相關問題