奇怪的 py2exe 错误
我用 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.glob(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()
当我运行它时,我在控制台中得到以下内容:
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'
我很确定它的源代码来自我的其他音乐下载程序。 我已经尝试过重新安装Python、重新安装py2exe并扫描病毒。
我使用的是 Win 64 Python 2.7.1 Windows 7。
有谁知道为什么我会收到此错误?
没关系,我再次将其编译成 exe 后再次运行它,它的工作效果很奇怪。
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.glob(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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 模块的名称中不能包含破折号。而且你不能调用Python模块
zipfile
,因为已经有一个标准具有该名称的库模块。如果在运行 py2exe 之前将其重命名为 z.py 是否有效?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 toz.py
, before you runpy2exe
?