2016-02-28 115 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

相关问题