奇怪的 py2exe 错误

发布于 2024-11-10 07:05:35 字数 1379 浏览 2 评论 0原文

我用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尤怨 2024-11-17 07:05:35

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 to z.py, before you run py2exe?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文