py2exe单个可执行文件不起作用

时间:2017-02-20 16:35:45

标签: python error-handling py2exe

我正在尝试使用py2exe生成单个可执行文件,没有依赖项。使用标准的setup.py文件和exe的所有依赖项,但是当我尝试修改setup.py以生成单个exe时,会生成.exe文件但是当我单击它时不起作用。 这是我的python脚本的代码:

# ======== Select a directory:

import Tkinter, tkFileDialog

root = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please  select a directory')
if len(dirname ) > 0:
    print "You chose %s" % dirname 


# ======== Select a file for opening:
import Tkinter,tkFileDialog
import sys
import ntpath
import os

root = Tkinter.Tk()
file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file')
if file != None:
    reader = file
    print type(str(reader.name))
    output_name= os.path.splitext(os.path.basename(str(reader.name)))[0]
    writer = open(output_name+'_Elaborata.txt','w')


    count = 1
    countbis = 0
    index = 0
    c = 0
    listaindex = []
    firstline = 1
    flag = False

    a = ''.join([chr(n) for n in range(256)])
    b = ''.join([n for n in a if ord(n) >= 32 and ord(n) <= 126])
    c = ''.join([n for n in a if ord(n) < 32 or ord(n) > 126])
    #print a
    arraychar = []

    #for n in range(256):
        #if(n >= 32 and n <= 126):
        #   print n, chr(n)
        #else:
            #arraychar.append(chr(n))

    result = "".join([(" " if n in c else n) for n in a if n not in c])

    #print a
    #print result

    #print arraychar
    listaelem=[]


    with reader as f:
        for _ in xrange(3):
            next(f)
        for line in f:
            if('-------' in line):
                continue
            if(line.strip() != ''):
                lista = line.split("|")
                if(len(lista) != 10):
                    pass
                    #print len(lista), line.strip()
                lista2 = []
                for elem in lista:
                    #Pulitura singola linea da caratteri speciali
                    result = "".join([("" if n in c else n) for n in elem.strip() if n not in c])
                    lista2.append(result.strip())
                if len(lista2) != 10:
                    #print line.strip()
                    pass
                string = ""
                for elem in lista2:
                    string += elem + "|"

                writer.write(string[:-1]+"\n")

    reader.close()
    writer.close()

哪个setup.py可以正确生成一个.exe文件?

这是setup.py:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "single.py"}],
    zipfile = None,
)

0 个答案:

没有答案