Pyinstaller throw error没有这样的文件或目录

时间:2016-02-28 17:02:21

标签: python windows executable pyinstaller

我编写了一个简单的python文件,我试图读取文本文件并将一些日志写入输出文件。使用pyinstaller我创建了一个.exe文件。但是当我执行该.exe文件时,它会抛出以下错误。

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操作系统,例如win 8,8.1,10等。

1 个答案:

答案 0 :(得分:1)

.exe不在.exe所在的文件夹中,或者input1.txt希望您将onefile/singlefile打包到其中 - Thread thread = new Thread(new Runnable(){ @Override public void run() { try { try { FileOutputStream f = new FileOutputStream(directory); URL u = new URL(fileURL); c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); //c.setRequestProperty("Content-Type", "application/pdf"); //c.setDoOutput(true); c.connect(); Log.d("debugz", Integer.toString(c.getContentLength())); InputStream in = c.getInputStream(); byte[] buffer = new byte[1024]; int len1 = 0; while ((len1 = in.read(buffer)) > 0) { f.write(buffer, 0, len1); } f.flush(); f.getFD().sync(); f.close(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } } }); thread.start(); pyinstaller中的选项。