weird py2exe error
I made this code into an executable with py2exe:
# File: zipfile-example-1.py
from Tkinter import *
import zipfile
import os
import glob
Admin = Tk()
Admin.configure(bg='grey')
La = Label(Admin,bg='grey', text='Dir to back up.')
La.pack()
Ent = Entry(Admin, bg='grey')
Ent.pack()
la = Label(Admin,bg='grey', text='Zip file name.')
la.pack()
ent = Entry(Admin,bg='grey')
ent.pack()
def zipdir():
fi = ent.get()
fii = fi+'.zip'
pl = Ent.get()
pll = pl+'/*'
file = zipfile.ZipFile(fii, "w")
# list filenames
for name in glob.g开发者_开发百科lob(pll):
print name
file.write(name,os.path.basename(name),zipfile.ZIP_DEFLATED)
file.close()
file = zipfile.ZipFile(fii, "r")
for info in file.infolist():
print info.filename, info.date_time, info.file_size, info.compress_size
Bu = Button(Admin,text='Backup.',command=zipdir)
Bu.pack(side=RIGHT)
Admin.mainloop()
When I run it I get this in the console:
Traceback (most recent call last):
File "zip.py", line 3, in <module>
File "zipfile.pyc", line 462, in <module>
File "zipfile.pyc", line 474, in ZipExtFile
AttributeError: 'module' object has no attribute 'compile'
Im pretty sure its source code from my other music downloading program. I've already tried to reinstall Python, reinstall py2exe and scanned for viruses.
I'm using Win 64 Python 2.7.1 Windows 7.
Does anyone know why I get this error?
Never mind i ran it again after compiling it into a exe again and it worked odly enough.
You can't have dashes in the name of a Python module. And you can't call a Python module zipfile
, because there's already a standard library module with that name. Does it work if you rename it to z.py
, before you run py2exe
?
精彩评论