简体   繁体   English

创建带有 Pyinstaller 问题的 Python Tkinter exe 文件问题

[英]Creating Python Tkinter exe file with Pyinstaller problem

I have created GUI python2.7 program with Tkinter successfully without error.我已经成功创建了带有 Tkinter 的 GUI python2.7 程序,没有错误。 Now I want to make an executable file of it using pyinstaller in anaconda environment (I'm using windows 10).现在我想在 anaconda 环境中使用 pyinstaller 制作它的可执行文件(我使用的是 windows 10)。

Using this command pyinstaller --onefile main.py I am able to create exe file successfully in dist folder.使用此命令pyinstaller --onefile main.py我可以在 dist 文件夹中成功创建 exe 文件。 But when I tried to run the exe file, it showed error:但是当我尝试运行exe文件时,它显示错误:

Traceback (most recent call last):   
File "main.py", line 333, in <module>   
File "main.py", line 90, in __init__   
File "lib-tk\ttk.py", line 715, in current
_tkinter.TclError: Index 0 out of range 
[22668] Failed to execute script main

Is the problem related to tkinter?问题是否与 tkinter 有关? I've tried the solution here: Problems with Pyinstaller with tkinter app on python 3.5 and here: How to make pyinstaller import the ttk theme?我在这里尝试了解决方案: python 3.5 上的 tkinter 应用程序的 Pyinstaller 问题和这里: 如何让 pyinstaller 导入 ttk 主题? . . But still same error但还是同样的错误

Try and do:尝试做:

pyinstaller --onefile -w main.py pyinstaller --onefile -w main.py

The -w flag stops python from bringing up the console, and so this could be why tkinter is failing. -w 标志阻止 python 启动控制台,所以这可能是 tkinter 失败的原因。

Source: This cool video来源:这个很酷的视频

I highly recommend you watch this video as it also goes a little in depth on how to clean up after building the exe.我强烈建议您观看此视频,因为它还深入介绍了构建 exe 后如何进行清理。

I used pyinstaller to create single exe file for a tkinter project, which contained several py files:我使用pyinstallertkinter项目创建了单个 exe 文件,其中包含几个 py 文件:

Main.py is my main python file which calls tkinter UI and I had several other python files imported to this Main.py. Main.py 是我的主要 python 文件,它调用 tkinter UI,我有几个其他 python 文件导入到这个 Main.py。 Some libraries which I used include pandas,pyodbc我使用的一些库包括 pandas,pyodbc

Open cmd in the same directory of the project;打开工程同目录下的cmd; Use following command:使用以下命令:

pyinstaller --noconfirm --onedir --windowed --icon=XYZ.ico "C:/Users/.../Tkinter_Project/Main.py"

Application was created with no dependencies.应用程序是在没有依赖关系的情况下创建的。 If there is any config or image files used, simply copy paste it to the 'dist' folder which gets created.如果使用了任何配置或图像文件,只需将其复制粘贴到创建的“dist”文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM