【问题标题】:InportError after running py2exe on python 3 app using Tkinter使用 Tkinter 在 python 3 应用程序上运行 py2exe 后出现 InportError
【发布时间】:2021-02-21 21:07:22
【问题描述】:

我在 python 3.7 中使用 tkinter 编写了一个简单的应用程序,它在 tkinter 中似乎编译得很好em>py2exe。当我尝试运行它时,出现以下错误:

这是错误:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
  File "tkinter\__init__.pyc", line 36, in <module>
  File "<loader>", line 10, in <module>
  File "<loader>", line 8, in __load
ImportError: (DLL load failed: %1 is not a valid Win32 application.) 'C:\\Users\\i30103\\PycharmProjects\\emailpars\\dist\\_tkinter.pyd'

代码如下:

from tkinter import *

# Main Program
if __name__ == '__main__':
    window = Tk()
    window.title("Welcome to LikeGeeks app")
    window.geometry('350x200')
    lbl = Label(window, text="Hello")
    lbl.grid(column=0, row=0)

    def clicked():

        lbl.configure(text="Button was clicked !!")

    btn = Button(window, text="Click Me", command=clicked)
    btn.grid(column=1, row=0)
    window.mainloop()

这是设置文件:

from distutils.core import setup
import py2exe

setup(console=['main.py'])

这是有关应用程序和我的系统的信息

我正在运行具有 64 位操作系统的 Windows 10 计算机。

我正在运行 python 3.7 32 位版本。 "Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32"

py2exe 在没有 tkinter 的情况下可以正常工作,但我正在尝试制作一个 GUI 应用程序。有什么想法吗?

【问题讨论】:

  • 这能回答你的问题吗? ImportError DLL load failed importing _tkinter
  • 顺便说一句,使用import * 通常是不好的做法。
  • 是的,我同意。这是我正在使用的一些演示代码,我没有时间重写它。

标签: python python-3.x tkinter importerror py2exe


【解决方案1】:

我尝试卸载并重新安装 Python,发现公司计算机已将 Python 作为映像的一部分安装,并且已删除卸载。此问题可能是通过对笔记本电脑进行映像自定义安装 python 引起的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多