-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from Embarcadero/pyinstaller_sample
PyInstaller sample
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import delphivcl | ||
input(delphivcl.__spec__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- mode: python ; coding: utf-8 -*- | ||
|
||
|
||
a = Analysis( | ||
['delphivclexecutable.py'], | ||
pathex=[], | ||
binaries=[], | ||
datas=[(r"C:\Users\lmbelo\AppData\Local\Programs\Python\Python311\Lib\site-packages\delphivcl", "delphivcl")], | ||
hiddenimports=[], | ||
hookspath=[], | ||
hooksconfig={}, | ||
runtime_hooks=[], | ||
excludes=[], | ||
noarchive=False, | ||
) | ||
pyz = PYZ(a.pure) | ||
|
||
exe = EXE( | ||
pyz, | ||
a.scripts, | ||
[], | ||
exclude_binaries=True, | ||
name='delphivclexecutable', | ||
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='delphivclexecutable', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
DelphiVCL4Python - PyInstaller Sample[]() | ||
# DelphiVCL4Python - 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 delphivcl as follows (use terminal): | ||
``` | ||
python -m pip install delphivcl | ||
``` | ||
|
||
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 "delphivclexecutable.py". Edit the "delphivclexecutable.py" content to look like follows: | ||
|
||
``` | ||
import delphivcl | ||
input(delphivcl.__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 delphivclexecutable.py | ||
``` | ||
|
||
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: | ||
|
||
``` | ||
(r"<<<<THE DELPHI VCL FOLDER IN YOUR SITE-PACKAGES>>>>", "delphivcl") | ||
``` | ||
|
||
This is how it looks to me: | ||
|
||
``` | ||
... | ||
datas=[(r"C:\Users\lmbelo\AppData\Local\Programs\Python\Python311\Lib\site-packages\delphivcl", "delphivcl")], | ||
... | ||
``` | ||
Note: you can remove the "docs" folder from delphivcl to make it smaller. | ||
|
||
## Build your executable | ||
|
||
We're now ready to build the exectable. Use the following command in Terminal to proceed: | ||
|
||
``` | ||
pyinstaller delphivclexecutable.spec | ||
``` | ||
|
||
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. |