Use Nuitka to pack flet desktop app #1314
Replies: 6 comments 3 replies
-
Thanks for your efforts! Is there any way for Nuitka to include additional files/resources (like Flet viewer app) to the produced package? |
Beta Was this translation helpful? Give feedback.
-
Hi ningzichun, I have a question, how to set the app icon, I has packed a app success by nuitka, but the app icon is flet's icon. I know, this is a flet.app, my app is a ui-element. I reviewed the flet code and found the 'update_flet_view_icon' function in pack.py, is it to set the flet.app's icon? |
Beta Was this translation helpful? Give feedback.
-
Wow, I did it! I modified the icon, name, and other information of flet.app through the below code, and then packaged it using Nuitka. I'm wondering if I can submit a pull request to implement a like-"packn" command to achieve this function. PS: The app packaged by Nuitka starts up much faster than the one packaged by PyInstaller. if sys.platform == "darwin":
app_name = 'fletx'
icon_path = './icon.png'
from flet.__pyinstaller.macos_utils import (
assemble_app_bundle,
unpack_app_bundle,
update_flet_view_icon,
update_flet_view_version_info,
)
# bin path
bin_path = get_flet_bin_path()
try:
# copy "bin"
hook_config.temp_bin_dir = copy_flet_bin()
print(f'temp dir:{hook_config.temp_bin_dir}')
# modify flet icon and info
tar_path = os.path.join(
get_flet_bin_path(), "flet-macos-amd64.tar.gz"
)
# unpack
app_path = unpack_app_bundle(tar_path)
# icon
if not Path(icon_path).is_absolute():
icon_path = str(Path(os.getcwd()).joinpath(icon_path))
update_flet_view_icon(app_path, icon_path)
# version info
app_path = update_flet_view_version_info(
app_path=app_path,
bundle_id=None,
product_name=app_name,
product_version=None,
copyright=None,
)
# assemble
assemble_app_bundle(app_path, tar_path)
# package, use modified flet app
cmd = f'''
python -m nuitka --follow-imports --standalone --macos-create-app-bundle --output-dir=dist \
--enable-plugin=numpy \
--macos-app-icon={icon_path} \
--product-name={app_name} \
--include-data-dir=poppler=poppler \
--macos-app-mode=ui-element \
--include-package-data=flet \
main.py
'''
print(cmd)
os.system(cmd)
# remove flet temp bin
Path.home().joinpath(".flet", "bin", f"flet-{version.version}")
except Exception as e:
print(e)
finally:
# recover flet bin
shutil.copy(Path(hook_config.temp_bin_dir) / 'flet-macos-amd64.tar.gz', Path(bin_path) / 'flet-macos-amd64.tar.gz')
# cleanup
if hook_config.temp_bin_dir is not None and os.path.exists(
hook_config.temp_bin_dir
):
print("Deleting temp directory:", hook_config.temp_bin_dir)
shutil.rmtree(hook_config.temp_bin_dir, ignore_errors=True) |
Beta Was this translation helpful? Give feedback.
-
I optimized the packaging logic by using temporary flet/bin instead of modifying the information of the original package.
|
Beta Was this translation helpful? Give feedback.
-
hello, I used the nuitka_flet.yml you provided, but i find some .dll files will be packed twice in executable file root directorey and flet.exe directory such as flutter_windows.dll and vcruntime.dll, is there any optimization? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I have successfully used Nuitka to pack flet desktop app (tested on flet-0.5.2, Nuitka-1.5.6 and Python-3.11). I think it is absolutely faster than the pyinstaller on MacOS cause it is onedir mode. And I found pyinstaller might have trouble collecting some libraries on Linux, so I looked back and try Nuitka again, seeking for better speed and compatibility.
Minimal Testcase
Here is the minimal command I used to test the code:
MacOS:
Linux:
Windows:
A bit tricky because Nuitka will ignore the *.dll, *.so in the module data directory when using
--include-package-data
, so to avoid downloading flet.exe on startup and to include needed dlls and app.so, we will create a Nuitka Package Configurarion such asscripts/nuitka_flet.yml
with:Then we run the command to compile:
For Production
Also, I would like to share the full command I used to build my project in the buildbot:
MacOS:
Linux:
Windows:
To be updated with more tests, like trimming the included data...
Beta Was this translation helpful? Give feedback.
All reactions