简体   繁体   中英

Creating Python Tkinter exe file with Pyinstaller problem

I have created GUI python2.7 program with Tkinter successfully without error. Now I want to make an executable file of it using pyinstaller in anaconda environment (I'm using windows 10).

Using this command pyinstaller --onefile main.py I am able to create exe file successfully in dist folder. But when I tried to run the exe file, it showed error:

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? 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? . But still same error

Try and do:

pyinstaller --onefile -w main.py

The -w flag stops python from bringing up the console, and so this could be why tkinter is failing.

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.

I used pyinstaller to create single exe file for a tkinter project, which contained several py files:

Main.py is my main python file which calls tkinter UI and I had several other python files imported to this Main.py. Some libraries which I used include pandas,pyodbc

Open cmd in the same directory of the project; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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