Create your own app for Apple macOS and more.
We need NodeJS and Python.
- For
npmget a look here: Best practice - For
pythonget a look here: Best practice
For NPM:
$ npm install -g create-dmgFor python:
$ pip3 install pyinstallerOR
$ pip3 install -r requirements.txtYou can list your packages here:
requirements.txt
pyinstaller Create example.py
import tkinter as tk def say_hello(): print("Hello, World!") app = tk.Tk() app.title("Simple App") hello_button = tk.Button(app, text="Say Hello", command=say_hello) hello_button.pack(pady=20) app.mainloop()And then packaging with PyInstaller:
$ pyinstaller --onefile --windowed example.pyAnd now create from dist folder your app:
$ create-dmg dist/example.appYou see this message after creating without a code signing:
β No suitable code signing identity foundRun create-dmg with the --no-skip-checks option to skip code signing:
create-dmg dist/example.app --no-skip-checksHowever, there are also some free options if you just want to test apps on your own device or do not plan on official distribution via the App Store.
You can create a free Apple Developer account to test apps on your own devices. This has some limitations, such as the need to renew the certificate every seven days, but it is sufficient for basic testing.
- Download Xcode from the Mac App Store.
- Open Xcode and go to Xcode > Preferences > Accounts.
- Go to the project's "Signing & Capabilities".
- Select your Apple ID profile from the team drop-down menu.
- Xcode automatically creates a signed certificate for you if you use the free developer account.
codesign --deep --force --verify --verbose --sign "Developer ID Application: Your Name (Team ID)" dist/example.appAfter codesign
$ create-dmg dist/example.appIf you want code signing, create a Apple Developer Account and join Apple Developer Program currently costs $99 per year.
Once you're a member, you can create certificates and provisioning profiles needed to sign and publish your apps.
- Sign in to the Apple Developer Account.
- Go to the Certificates, IDs & Profiles section.
- Create a Developer ID Application certificate for signing apps outside of the Mac App Store.
Sign the app:
After you've created and downloaded the certificate, open the Keychain Access app on your Mac and import the certificate.
$ codesign --deep --force --verify --verbose --sign "Developer ID Application: Your Name (Team ID)" dist/example.appAfter codesign
$ create-dmg dist/example.appNotes:
- Using your private Apple ID: When you use your private Apple ID, all apps and certificates are connected to your personal information.
If you don't want this, you can create a separate Apple ID just for development.
- Team ID: The Team ID is a unique identifier assigned to you when you join the Apple Developer Program. You can find this in your Apple Developer Account.
Do you have more than one file or multiple files for your program?
python-mac-app/ βββ main.py βββ module1.py βββ module2.py βββ python-mac-app.spec βββ assets/ β βββ image.png β βββ data.json βββ ... Create the python-mac-app.spec
# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis( ['main.py'], pathex=['./python-mac-app'], binaries=[], datas=[ ('assets/image.png', 'assets'), ('assets/data.json', 'assets') ], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False ) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, [], exclude_binaries=True, name='main', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False ) coll = COLLECT( exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='main' ) And now use the spec file to create your app:
$ pyinstaller python-mac-app.specAnd then create from dist folder your app:
$ create-dmg dist/python-mac-app.appPlease use the issue tab to request a:
- Bug
- Feature
Choose template and report a bug or feature you want issues.
Please read the contributing to contribute.
Please use the Security section for privately reporting a vulnerability.
