|
| 1 | +DelphiVCL4Python - PyInstaller Sample[]() |
| 2 | +# DelphiVCL4Python - PyInstaller Sample |
| 3 | + |
| 4 | + |
| 5 | +This is a sample that shows the use of the [PyInstaller](https://pyinstaller.org/en/stable/) package to create executables. |
| 6 | +## Contents |
| 7 | + |
| 8 | +* [1 Creating your app](#creating_your_app) |
| 9 | +* [2 Making the PyInstaller spec file](#making_pyinstaller_spec_file) |
| 10 | +* [3 Build your executable](#build_your_executable) |
| 11 | + |
| 12 | +## Creating your app |
| 13 | + |
| 14 | +First thing first, install delphivcl as follows (use terminal): |
| 15 | +``` |
| 16 | +python -m pip install delphivcl |
| 17 | +``` |
| 18 | + |
| 19 | +Now let's install PyInstaller: |
| 20 | +``` |
| 21 | +python -m pip install pyinstaller |
| 22 | +``` |
| 23 | + |
| 24 | +Create a new folder and call it "installer". Inside your project folder, create a file called "delphivclexecutable.py". Edit the "delphivclexecutable.py" content to look like follows: |
| 25 | + |
| 26 | +``` |
| 27 | +import delphivcl |
| 28 | +input(delphivcl.__spec__) |
| 29 | +``` |
| 30 | + |
| 31 | +## Making the PyInstaller spec file |
| 32 | + |
| 33 | +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: |
| 34 | + |
| 35 | +``` |
| 36 | +cd installer |
| 37 | +pyi-makespec delphivclexecutable.py |
| 38 | +``` |
| 39 | + |
| 40 | +Now we need to setup the spec file to distribute the DelphiVCL package. Open the spec file and include the following code in the data list: |
| 41 | + |
| 42 | +``` |
| 43 | +(r"<<<<THE DELPHI VCL FOLDER IN YOUR SITE-PACKAGES>>>>", "delphivcl") |
| 44 | +``` |
| 45 | + |
| 46 | +This is how it looks to me: |
| 47 | + |
| 48 | +``` |
| 49 | +... |
| 50 | +datas=[(r"C:\Users\lmbelo\AppData\Local\Programs\Python\Python311\Lib\site-packages\delphivcl", "delphivcl")], |
| 51 | +... |
| 52 | +``` |
| 53 | +Note: you can remove the "docs" folder from delphivcl to make it smaller. |
| 54 | + |
| 55 | +## Build your executable |
| 56 | + |
| 57 | +We're now ready to build the exectable. Use the following command in Terminal to proceed: |
| 58 | + |
| 59 | +``` |
| 60 | +pyinstaller delphivclexecutable.spec |
| 61 | +``` |
| 62 | + |
| 63 | +After that, you will see the dist folder within project's folder. The executable file will be available as "delphivclexecutable.exe". You can customize the spec file as needed. |
0 commit comments