I have created a Python script, which uses customtkinter for a GUI where the user can select some options.
Here is an overview about the imported packages: used libraries
Everything works properly when I run the script in Pycharm (Community Edition 2021.1.2) and the GUI shows up as expected.
But after building (creating an exe from the script) using pyinstaller and running the exe I get following error message: Error when running exe file
Line 403 makes a problem acc. to this message - the corresponding line in the script looks like: Line 403 causes error
For building the exe I use following command: pyinstaller --noconfirm --onedir --windowed --add-data c:\users\myName\appdata\local\programs\python\python39\lib\site-packages\customtkinter;customtkinter\ DataAnalysisTool.py
Hope somebody can help!
I would expect that the exe file also runs as the script in Pycharm runs without any problem.
Update: minimum reproducible example (throws same error message when running exe)
import customtkinter
# create the root window
root_file = customtkinter.CTk()
root_file.title('Data Analysis Tool - File Selection')
root_file.resizable(False, False)
root_file.geometry('350x150')
root_file.mainloop()
I was able to compile your example code with the following steps:
Create a new virtual environment and install customtkinter
and pyinstaller
create a main.py file with your example code.
import customtkinter
# create the root window
root_file = customtkinter.CTk()
root_file.title('Data Analysis Tool - File Selection')
root_file.resizable(False, False)
root_file.geometry('350x150')
root_file.mainloop()
pyinstaller -F main.py --collect-all customtkinter
The compiled executable runs without error.
It works using the --onedir
option as well.