From 0a99ed341ca92eb1df4d409bdb14e9dc60ba3a73 Mon Sep 17 00:00:00 2001 From: lmbelo Date: Tue, 19 Dec 2023 09:34:09 -0300 Subject: [PATCH] PyInstaller sample --- samples/Installer/delphifmxexecutable.py | 2 + samples/Installer/delphifmxexecutable.spec | 43 +++++++++++++++ samples/Installer/readme.md | 63 ++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 samples/Installer/delphifmxexecutable.py create mode 100644 samples/Installer/delphifmxexecutable.spec create mode 100644 samples/Installer/readme.md diff --git a/samples/Installer/delphifmxexecutable.py b/samples/Installer/delphifmxexecutable.py new file mode 100644 index 0000000..30d5bbb --- /dev/null +++ b/samples/Installer/delphifmxexecutable.py @@ -0,0 +1,2 @@ +import delphifmx +input(delphifmx.__spec__) \ No newline at end of file diff --git a/samples/Installer/delphifmxexecutable.spec b/samples/Installer/delphifmxexecutable.spec new file mode 100644 index 0000000..ec0c6f8 --- /dev/null +++ b/samples/Installer/delphifmxexecutable.spec @@ -0,0 +1,43 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['delphifmxexecutable.py'], + pathex=[], + binaries=[], + datas=[(r"C:\Users\lmbelo\AppData\Local\Programs\Python\Python311\Lib\site-packages\delphifmx", "delphifmx")], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + noarchive=False, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='delphifmxexecutable', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT( + exe, + a.binaries, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='delphifmxexecutable', +) diff --git a/samples/Installer/readme.md b/samples/Installer/readme.md new file mode 100644 index 0000000..b68c063 --- /dev/null +++ b/samples/Installer/readme.md @@ -0,0 +1,63 @@ +DelphiFMX4Python - PyInstaller Sample[]() +# DelphiFMX4Python - PyInstaller Sample + + +This is a sample that shows the use of the [PyInstaller](https://pyinstaller.org/en/stable/) package to create executables. +## Contents + +* [1 Creating your app](#creating_your_app) +* [2 Making the PyInstaller spec file](#making_pyinstaller_spec_file) +* [3 Build your executable](#build_your_executable) + +## Creating your app + +First thing first, install delphifmx as follows (use terminal): +``` +python -m pip install delphifmx +``` + +Now let's install PyInstaller: +``` +python -m pip install pyinstaller +``` + +Create a new folder and call it "installer". Inside your project folder, create a file called "delphifmxexecutable.py". Edit the "delphifmxexecutable.py" content to look like follows: + +``` +import delphifmx +input(delphifmx.__spec__) +``` + +## Making the PyInstaller spec file + +Using a spec file will simplify your next buildings. Let's create a new spec file based upon project's main script file. In Terminal, run the following: + +``` +cd installer +pyi-makespec delphifmxexecutable.py +``` + +Now we need to setup the spec file to distribute the DelphiFMX package. Open the spec file and include the following code in the data list: + +``` +(r"<<<>>>", "delphifmx") +``` + +This is how it looks to me: + +``` +... +datas=[(r"C:\Users\lmbelo\AppData\Local\Programs\Python\Python311\Lib\site-packages\delphifmx", "delphifmx")], +... +``` +Note: you can remove the "docs" folder from delphifmx to make it smaller. + +## Build your executable + +We're now ready to build the exectable. Use the following command in Terminal to proceed: + +``` +pyinstaller delphifmxexecutable.spec +``` + +After that, you will see the dist folder within project's folder. The executable file will be available as "delphifmxexecutable.exe". You can customize the spec file as needed. \ No newline at end of file