Replies: 17 comments 29 replies
-
Hi, I have one config.yml which user can edit and I want to ship it along with the exe and not inside the temp folder. Can you show how to achieve this? If I add config.yml it gets bundled with the exe. I want it to be outside exe and should be readable from exe |
Beta Was this translation helpful? Give feedback.
-
With following configuration you can deploy your app as 'onefile' or 'onedirectory' option, both options work fine. |
Beta Was this translation helpful? Give feedback.
-
for nuitka on windows:
```
nuitka file.py --standalone --onefile --disable-console --include-package-data=customtkinter --enable-plugin=tk-inter
```
works,
and on linux(where you have the customtkinter folder in the current
directory),
```
python3 -m nuitka file.py --standalone --onefile --include-package-data=customtkinter --enable-plugin=tk-inter --include-data-dir=./customtkinter=./customtkinter
```
|
Beta Was this translation helpful? Give feedback.
-
If you're using tkcalendar inside CTk UI then you'll have to add follwing This is because pyinstaller does not include babel libraries by default. We have to manually import them while packaging. |
Beta Was this translation helpful? Give feedback.
-
Another pro tip for Sometimes you may have large libraries and modules included in the one-exe file which results in slower startup time. In that case you can exclude some module folders outside the main exe file with some tweaks: Here is how you can do it:
# add this code in the top (before imports)
import sys, os
if getattr(sys, 'frozen', False):
app_path = os.path.join(os.path.dirname(sys.executable), "Modules")
sys.path.append(app_path) # search this path for modules
This will reduce the startup time and size of the executable |
Beta Was this translation helpful? Give feedback.
-
please i'm using cx_freeze to package my python script how do i include the path of the customtkinter import sys """Copyright (c) 2023 Kennart Tech""" ---------------------------------------------------------------------build_exe_options = { ----------------------------------------------------------------------------------------------------------------------------------------shortcut_table = [#This defines the shorcut to be created for the frozen executable msi_data = {"Shortcut": shortcut_table} -----------------------------------------------------------------------------------------------------------------------------------base = None #this will set the base of the application to a GUI application on Windows. ------------------------------------------------------------------------------------------------------------------------------------------script_path = "CALCULATOR.py" # Replace with the path to your Python script -----------------------------------------------------------------------------------------------------------------------------------------------setup( ---------------------------------------------------------------------------- |
Beta Was this translation helpful? Give feedback.
-
Did anyone explore the codon compiler? |
Beta Was this translation helpful? Give feedback.
-
Pro-Tip for one-file mode: Generally the temp folder for one file mode (named like But there is an option for the one-file mode in which the temp folder spawn location can be changed. Under Advanced tab there is an option called Now, the temp folder will be extracted in the same directory where the exe is present (inside a new 'temp' dir). In this case, users can easily find and delete that temp folder if the app crashes. So, it is just good for the user side specially if your app is in experimental stage. Disadvantage: The app will not open if the user runs the exe inside any read-only location having no access to write. |
Beta Was this translation helpful? Give feedback.
-
I'm brand new to all this, and I've found both the ofifcial wiki and this improved wiki very helpful and informative. |
Beta Was this translation helpful? Give feedback.
-
with nuitka you guys noticed any performance improvements? |
Beta Was this translation helpful? Give feedback.
-
@Akascape Thank you for the updated documentation! Does this tutorial work for macOS? I'm hoping to get guided through the process if that's not too much to ask! |
Beta Was this translation helpful? Give feedback.
-
@Akascape I'm running into an issue when opening the finished app. Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help! I was able to successfully package it! :) |
Beta Was this translation helpful? Give feedback.
-
I have no problems compiling normally, but I noticed that CTkSwitch and CTkScrollableFrame, show an error when creating onefile.
And from 'CTkScrollableFrame', it shows me:
|
Beta Was this translation helpful? Give feedback.
-
Full Video guide: |
Beta Was this translation helpful? Give feedback.
-
After formatting my pc, I get this issue when packaging for some reason when it was working before. FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\...\AppData\Local\Temp\_MEI118322\../Assets/icon.ico' |
Beta Was this translation helpful? Give feedback.
-
Packaging
When you are creating an executable with pyinstaller, then there are some things you have to consider. It is recommended to use Auto-py-to-exe which is an easy interface for pyinstaller.
One-Dir or One-File?
First add your main python program in the
script location
option.Then you will have to choose between two options:
One Directory
andOne File
.Packaging with one-directory:
This mode will give a folder where you will get lots of files including the exe. The main benefit of using one-dir is that you will get a faster loading executable with all the folders in one place.
But the problem is that the folder looks ugly with so many files, you may have to use some exe-installer/setup creater.
(If you are using this mode, then skip the one-file part)
Packaging with one-file:
With this mode, you will get a single executable file. When you run that executable, a temp folder (named as _MEIPASS...), will be created in a OS defined temp location where it will extract all the necessary files that we used to get with the one-dir mode. This unpacking is done every time when you open that executable which affects the startup time. This is how the one-file mode works.
Packing external files with one-file mode:
Generally, if you are using any external assets like images, sub-folders or any other files, then you will need to keep that asset outside the one-exe file.
But if you want to pack those assets/folders inside that one-exe file, then you will have to do a little tweak in your program.
To do this, you have to first add those assets/folders under the additional files option of pyinstaller.
Then you will have to change the search method for all assets in your program:
If you are importing an asset like this:
Then change it to this:
_Note: Make sure that the file paths are relative, avoid uses of slash, instead use
os.path.join
method _We are doing this because the one-file exe unpacks its files in a separate temp directory when it is executed. So, you have to use this method to search the packed files within that hidden temp folder.
If you want to reduce the size of one-file exe, then here is a pro-tip: #939 (comment)
Another pro tip if you want to change the default temp dir location: #939 (comment)
Console Window
Under this section, you will get two options:
console-based
andwindow-based
.Console-Based: You will get a console window running in the background with your main app.
However there is new option to hide/minimize the console automatically after startup, see pyinstaller/pyinstaller#7735 (write the code in additional arguments section)
Window-Based: You will only get the app window. (recommended for most applications)
Icon
Under the icon section, you can set the icon for your app. (Just add your
.ico
file)Note that this icon will not be shown inside the application titlebar.
To pack the custom icons read the next heading.
Additional Files and Folders
You can add all other assets/folders/modules accordingly with pyinstaller
You will have to add the folder
customtkinter
because pyinstaller doesn't automatically include datafiles like .json from the library.You can find the install location of the customtkinter library with the following command:
A location will be shown in the details, for example:
c:\users\<user_name>\appdata\local\programs\python\python310\lib\site-packages
, where you will find the customtkinter package.Similarly, for any other module import error, try to pack them separately like this.
For easier access, it is recommended to keep a copy of the module folders like customtkinter in the same directory where your python program is present.
Output
There are many other advanced options you can tweak if you research more about pyinstaller, like adding a splash screen image and runtime hooks.
Otherwise just move to the
Settings
section and choose yourOutput Directory
where the executable will be created.Then just click on
Convert
!That's all you need to know about packaging your customtkinter app to an executable file with pyinstaller.
Full Video guide:
Beta Was this translation helpful? Give feedback.
All reactions