pyinstaller 打包的程序在 win7 service pack1上运行报错
打包后的 exe 在win10、以及其他 win7 电脑上面测试都可以运行,但是就是有一些 win7专业版系统的电脑运行确报错。
测试环境:
OS:win7专业版 service pack1
Python: 3.8.5
以下是在 win7 专业版上运行报错内容:
Traceback (most recent call last):
File "demo.py", line 1, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "tkinter\__init__.py", line 36, in <module>
ImportError: DLL load failed while importing _tkinter: 参数错误。
demo.py 代码如下:
import tkinter as tk
root = tk.Tk()
toolbar = tk.Frame(root)
text = tk.Text(root, wrap="word", yscrollcommand=lambda *args: vsb.set(*args))
vsb = tk.Scrollbar(root, command=text.yview)
toolbar.pack(side="top", fill="x")
vsb.pack(side="right", fill="y")
text.pack(side="left", fill="both", expand=True)
COUNT = 0
def add_widget():
global COUNT
COUNT += 1
widget = tk.Label(root, width=12, text=f"Widget #{COUNT}", bd=1, relief="raised",
bg="#5C9BD5", foreground="white", padx=4, pady=4)
text.configure(state="normal")
text.window_create("insert", window=widget, padx=10, pady=10)
text.configure(state="disabled")
add_button = tk.Button(toolbar, command=add_widget, text="Add")
add_button.pack(side="left")
for i in range(9):
add_widget()
root.mainloop()
第一行是引入 tkinter 的包,看报错说明是引入 tkinter 包的时候加载 DLL 动态链接库失败导致的错误。
尝试了安装 VC redit.exe 还是不行。
可以正常运行的 win7 系统版本
运行报错的win7系统版本
用来测试可复现的 win7 系统版本
有遇到同样问题的大佬不,这种情况有没有什么好的解决办法(除了升级/重装系统之外的)
解决了!记录一下解决办法,查询资料有类似情况,可能是由于 win7 专业版 sp1 系统的原因。
blog.csdn.net/Bit_Coders/article/d...
通过该文章的内容,下载 KB2533623 补丁并在 win7 专业版 sp1 上安装后重启,运行就不会报错了~