Reputation: 193
I have written a simple python file where I am trying to read a text file and writing some log to a output file. Using pyinstaller I have created a .exe file. But when I am executing the that .exe file it is throwing the following error.
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
Here is my code.
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)
Can somebody tell me how to fix this one. I am doing this in Windows.
I also want to know whether this executable will work in all windows os like win 8, 8.1, 10 etc.
Upvotes: 0
Views: 2813
Reputation: 12199
Either input1.txt
is not in the folder where you have the .exe
, or the .exe
expects you to have input1.txt
packaged into it - that onefile/singlefile
option in pyinstaller.
Upvotes: 1