To support PyPi installers, this was moved to https://github.com/The-Nicholas-R-Barrow-Company-LLC/PyMacApp
pip3 install PyMacApp
Base project example to create an application with Python3 and PyInstaller, including all necessary build scripts.
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).
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.
You should have PyInstaller installed in a global or virtual environment (pip3 install pyinstaller
). This is the only Python dependency.
Alternatively, you can use pip3 install -r requirements.txt
.
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
- Open KeyChain Access
- Create a "New Password Item"
- Keychain Item Name: Developer-altool
- Account Name: your developer account email
- Password: the application-specific password you just created
- 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"
- 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 into the build file in
./build-scripts/build
There are explanatory comments next to each variable at the top of the ./build-scripts/build
as to what they represent. You must fill these out for this to work.
Additionally, you will need to configure two settings in the .spec file:
- 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
- at the way bottom, set the 'name' to the same as 'APP' in the ./build-scripts/build file
- at the way bottom, set bundle_identifier=
bundle_id_for_your_app
using the identifier for the .app
app = BUNDLE(coll, name='My New App.app', icon=None, bundle_identifier=bundle_id)
Begin to code your application in the ./app/app.py
file. When you are satisfied, proceed to the next section.
Individual scripts are provided in the ./build-scripts/
directory. Here, you can customize the individual level scripts so you can choose which process to run (i.e., you may want to build your .app for testing purposes and therefore do not want a .pkg or to notorize)
The main workflow is in ./build-scripts/build
and can be run with bash ./build-scripts/build
.
You can view the ./build-scripts/Scripts
directory to see what is included. You (as far as I know) cannot change the filenames. However, you can do almost anything you'd like inside them. The preinstall
is called, as it suggests, prior to installing, just as the postinstall
occurs after-the-fact. Currently, it defaults to no preinstall processes and one postinstall process which makes changes the program's permissions. NOTE: if the application does not have 777-style permissions, you will likely run into problems (as I did) because the app will not be able to write data; it is best to leave these alone unless you know what you're doing.