Project structure should look something like this:
EncryptionTool/
├── main.py # Your main script
├── encryptiontoolLogo.icns # Your application icon
├── requirements.txt # Python dependencies
└── README.md # Optional: Documentation
You’ll need the following tools:
- PyInstaller: To package your Python script into an executable.
- Create-dmg: To create a
.dmgfile for distribution.
Install them using pip and brew:
pip install pyinstaller
brew install create-dmgUse PyInstaller to create a standalone macOS application bundle.
-
Create a
.specfile for PyInstaller:pyinstaller --windowed --name EncryptionTool --icon encryptiontoolLogo.icns main.py
-
Edit the generated
EncryptionTool.specfile to include additional resources (e.g., icons, data files):# EncryptionTool.spec # -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['main.py'], pathex=['/path/to/EncryptionTool'], binaries=[], datas=[('encryptiontoolLogo.icns', '.')], # Include the icon file hiddenimports=[], hookspath=[], hooksconfig={}, runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, [], exclude_binaries=True, name='EncryptionTool', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False, disable_windowed_traceback=False, target_arch=None, codesign_identity=None, entitlements_file=None, ) coll = COLLECT( exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='EncryptionTool', ) app = BUNDLE( coll, name='EncryptionTool.app', icon='encryptiontoolLogo.icns', bundle_identifier='com.yourapp.encryptiontool', )
-
Run PyInstaller with the
.specfile:pyinstaller EncryptionTool.spec
This will create a dist/EncryptionTool.app bundle.
Navigate to the dist folder and double-click EncryptionTool.app to test it. Ensure everything works as expected.
Use create-dmg to create a .dmg file for distribution.
-
Create a directory structure for the DMG:
mkdir -p dmg/EncryptionTool cp -r dist/EncryptionTool.app dmg/EncryptionTool/
-
Run
create-dmg:create-dmg \ --volname "EncryptionTool" \ --volicon "encryptiontoolLogo.icns" \ --background "background.png" \ --window-pos 200 120 \ --window-size 800 400 \ --icon-size 100 \ --icon "EncryptionTool.app" 200 190 \ --hide-extension "EncryptionTool.app" \ --app-drop-link 600 185 \ "EncryptionTool.dmg" \ "dmg/"
This will create a EncryptionTool.dmg file in the current directory.
EncryptionTool/
├── main.py
├── encryptiontoolLogo.icns
├── EncryptionTool.spec
├── dist/
│ └── EncryptionTool.app
├── dmg/
│ └── EncryptionTool.app
└── EncryptionTool.dmg