pip3 install PyMacApp
This Repo creates a project that you can clone to streamline MacOS python desktop app development. It contains all necessary scripts to build your final project, as well as code-sign them from Apple (Developer Account required for some features).
from pymacapp.buildtools.app import App
from pymacapp.buildtools.package import Package
import os
# CREDENTIALS
APPLE_DEVELOPER_EMAIL = os.environ["APPLE_EMAIL"]
APPLE_DEVELOPER_TEAM_ID = os.environ["APPLE_DEVELOPER_TEAM_ID"]
APPLE_APP_SPECIFIC_PASSWORD = os.environ["APPLE_APP_SPECIFIC_PASSWORD"]
APP_HASH = App.get_first_hash()
PKG_HASH = Package.get_first_hash()
## APP
# create the app wrapper
app = App("My New App")
app.config("/path/to/main.py").build().sign(APP_HASH)
## PACKAGE
# create the package wrapper
package = Package(app, identifier="foo.bar")
# explicit authentication required starting in v.4.0.1
package.login(APPLE_DEVELOPER_EMAIL, APPLE_APP_SPECIFIC_PASSWORD, APPLE_DEVELOPER_TEAM_ID)
# begin processing
package.build().sign(Package.get_first_hash()).notarize()
package.log_full_notary_log()
package.staple()
This currently supports (and has been tested on) Python 3.9.9 on MacOS 11.6. This tool may work on other systems, but has not been tested. Feature (release phase):
- Building .app files (beta)
Adding custom files/resources to app files (alpha)[removed]- Custom URI Scheme & QApplication Class w/ Event Handler (alpha)
- Signing .app files (beta)
- Building .pkg files (beta)
- Signing .pkg files (alpha)
- Notarizing .pkg files (alpha)
- Stapling .pkg files (alpha)
- Custom build commands, natively in Python (beta)
pip3 install PyMacApp
- Uses PyInstaller, should install automatically
Make sure to have xcode installed, and verify that the xcode command line tools are installed:
xcode-select --install
Note: This section is taken from: https://gist.github.com/txoof/0636835d3cc65245c6288b2374799c43
- Go to https://developer.apple.com and shell out $99 for a developer account
- Download and install X-Code from the Apple App Store
- Open and run X-Code app and install whatever extras it requires
- Open the preferences pane (cmd+,)
- click the + in the lower right corner choose Apple ID
- enter your apple ID and password
- Instructions from Apple to create: https://support.apple.com/en-us/HT204397
- Save this password (you will need it for notorizing)
- Open XCode
- In the top-apple Menu, go to XCode > Preferences > Accounts > Your Account > In the team, chose the Admin team > Manage Certificates in the bottom-right
- click the plus in the bottom corner
- choose "Developer ID Application"
- repeating, click the plus in the bottom corner
- choose "Developer ID Installer"
Note: as of version 2.0.0, you should use the App.get_first_hash() and Package.get_first_hash()
to get your hashes in your build.py
script
- to manually get hashes, run:
security find-identity -p basic -v
- your output will look like:
- HASH_OF_ID_HERE "Developer ID Application: ..."
- HASH_OF_ID_HERE "Developer ID Installer: ..." > > 2 valid identities found
- copy the appropriate hashes or simply use
get_first_application_hash()
orget_first_installer_hash()
by importing them (from pymacapp.helpers import get_first_application_hash, get_first_installer_hash
)
- developer.apple.com
- choose "account" in top right
- login
- "Certificates, IDs, and Profiles"
- on the left, switch to "Identifiers"
- create two App IDs, one for your .app and one for your .pkg
- it may be helpful to do something like
com.your-domain.app-name
for the .app andcom.your-domain.app-name.pkg
for the .pkg
Code your app however you'd like. You'll need to identify a main script file (main.py or app.py); where ever you run your program from, that is your main script file.
Better docs coming soon; see example under Quickstart. Please feel free to email me (me@nicholasrbarrow.com) if you need advice on how I achieved this using PyMacApp.
This project began while performing work for Georgetown University's Department of Italian Studies. The code herein was needed to develop applications within the Department. Some of the code contains outside work, so this was a joint collaboration.
- major refactoring due to deprecation of
altool
, resolving #4 Package.notorize
method has been renamed toPackage.notarize
to fix this embarrassing typo- removed
Package.wait
method in favor ofPackage.notarize(wait: bool)
- Implicit authorization during
Package.notarize
, et al., removed in favor of an explicit call of thePackage.login
method (see the Quickstart for demo auth flow) - added an example build-example.py and example application under the example folder in the project root
- added changelog to readme
- updated readme's quick-start example
- cleaned the pymacapp directory (removed unsupported beta and old content)
- added docstrings to all functions of App and Package
- added function to output log if notary service fails during Package.notarize(...).wait(...)
- added alpha-feature: Resource (
from pymacapp import Resource
). This feature allows you to add custom files to your application using the App.resource(...) method.
- added alpha-feature: custom commands (
from pymacapp.custom import bash
) - note: Resource feature is experiencing bug that is not yet patched.
- patching release 1.2.1
- note: Resource feature is experiencing bug that is not yet patched.
- relocating custom commands (
from pymacapp.command import cmd
) and moving to beta - removing: Resource feature introduced in 1.2.0
- bug fixes
- moving some
subprocess
commands fromsubprocess.Popen(...)
to a custom function which usessubprocess.run(...)
- updating README
- added: new coverage for py-makespec (included with pyinstaller)
- deprecated: App.setup(...); see below
- added: App.config(...) to use new coverage for py-makespec
- minor bug fixes to new validators
- minor bug fixes to new coverage for py-makespec
- minor bug fixes to new coverage for py-makespec
- minor bug fixes to new coverage for py-makespec
- added:
pymacapp.versioning.VersionLocker
. This feature allows you to set a version (an unlimited-length string of non-negative integers delimited by periods ('.')) and pymacapp will store the version number in a file whenever its.lock()
method is called (this is useful so that you can decide when to lock the version (i.e. do not lock until after the app successfully builds, successfully packages, etc.)).
- reformatted major sections of the code to better structure the project for maintaining into the future
- completed migration to modern
subprocess
utilization
- fixed README to reflect 2.0.1 changes
- fixed a bug where default
entitlements.plist
did not package
- continuing to fix a bug where default
entitlements.plist
did not package
- continuing to fix a bug where default
entitlements.plist
did not package
- fixing bug related to Scripts collecting
- fixing bug related to Scripts collecting
- fixing bug related to Scripts being made executable in non-terminal environments (i.e. PyCharm)
- adds the ability to use
--hidden-import MODULENAME
and--collect-submodules MODULENAME
by passing lists of module names in theApp.config(...)
command
- adds the (alpha) ability to define a custom schema (
myappschema://...
) to access/launch the app from a web browser; define in theapp.config(..., url_schema="...")
- bug fixes for v.2.2.0
- bug fixes for v.2.2.1 that caused a faulty specpath
- bug fixes for v.2.2.2 that caused a faulty specpath by moving the custom url_schema to a plist modification post-build instead of modifying the spec file pre-build
- bug fixes for v.2.2.3
- major restructuring for the future of PyMacApp, now to include (a) buildtools and (b) runtools
pymacapp.buildtools
contains, at this point,app
andpackage
which are designed to aid in the creation of building, signing, and notorizing.app
and.pkg
filespymacaoo.runtools
is intended to contain tools for use in coding python applications- introduces CustomURIApplication, a subclass of QApplication for PySide6 to handle Custom URIs, pairing
with
url_schema
inApp.build
(from pymacapp.runtools import CustomURIApplication
)
- introduces CustomURIApplication, a subclass of QApplication for PySide6 to handle Custom URIs, pairing
with
- PyMacApp will now require PySide6 to support these new runtools
- relative import bug fixes
- bug fixes for setup.py
- adds the ability to set your own .spec file:
App.config(use_custom_spec='/path/to/file.spec')
- adds a URIRouter (
https://github.com/The-Nicholas-R-Barrow-Company-LLC/uri-router
orpip3 install URIRouter
) topymacapp.runtools.CustomURIApplication
- adds the ability to register the .app as having the ability to open extensions (.pdf, .docx, .txt, et cetera)
- v.3.2.0 bug fixes
- v.3.2.1 bug fixes