Python Macos Catalina

Python Macos Catalina

Python has an amazingly rich ecosystem of libraries, tools and frameworks. It is a clean, modern language, it allowsfor rapid prototyping and quick development cycles. UI was not the central, focal point of my app, so it made a lotof sense for me to do it in Python: I thought I’d write the core functionality first, and add the UI afterwards.

So in Catalina these runtimes will still be available. Also, from the same document. Use of Python 2.7 isn’t recommended. This version is included in macOS for compatibility with legacy software. Future versions of macOS won’t include Python 2.7. Instead, it’s recommended that you run python3 in Terminal.

MacOS Catalina (released in 2019) still does not have Python 3 installed by default, only Python 2. Therefore, I neededa way to package the whole application into an app bundle and not make it dependent on user’s Python installation.There are several tools that help with that: py2app,briefcase, pyinstaller. I decided to usePyInstaller, it’s mature, flexible, and offers more customization than the other options.

Python version macos catalinaCatalina

Step 1: PyInstaller spec file

PyInstaller can be driven by command-line options alone, but that works well for the simplest cases only, and packagingany non-trivial app is not one of these. I suggest running it with command-line parameters, which creates the spec filewith the default values, and then modifying the spec file to suit your needs better. For example, to set the bundleversion to the same value as the application version, and to add some custom plist values:

Step 2: Build the App

  1. How to setup python environment on macOS. On this page I describe how to setup python environment on macOS Catalina (10.13). When I upgrade to a next major version of macOS it's almost always some problems appear - some tools stop working, eapecially if you use your system for software development.
  2. The right and wrong way to set up Python 3 on MacOS, When I installed a module to tinker around with, I got a reminder that I needed to install Python 3 soon. $ pip install todoist-python Maria Campbell provides a post on installing the latest version of Python on Mac OS Catalina and overriding the old default pre-installed version.

This is as simple as

My Application.app will be created, which you can (and should) test to make sure it actually works. Some Pythonpackages require tweaks in PyInstaller spec file: including extra data files in the bundle, etc.

Step 3: Sign the App

In order to be able to notarize it, you must use the hardened run-time.The Hardened Runtime doesn’t affect the operation of most apps, but it does disallow certain capabilities. For Pythonapplications specifically, we need to allow unsigned executable memory. If your app relies on any other capabilitythat the Hardened Runtime restricts, add an entitlement to disable that individual protection as well.

Add entitlements.plist to your project’s root:

And now we’re ready to sign:

Macos Catalina Python 3

Note that in order to be able to notarize the app, you need to sign it with your Apple Developer IDcertificate. Adjust the “Developer” above to match your certificate name, if needed.

Apple recommends to not “deep-sign”, but in this case it’s actually required as all the bundled Python libraries doneed to be signed, not just your main binary.

By adding the --timestamp parameter we include a secure timestamp with the code-signing signature. This is arequirement for notarization.

By adding the entitlements file and passing a -o runtime parameter we enable the hardened runtime, which is alsoa requirement for notarization.

Step 3: Notarize the App

Catalina

In order to be able to notarize the app,you need to satisfy some additional requirements:

  • All the binaries in the application must be linked against macOS 10.9 or later SDK. If you just re-built everythingwith a recent Xcode, this requirement would be satisfied. If, however, you’re packaging some Python dependency witha pre-built binary extension, it might be built against an older SDK. In this case, you’ll need to build this specificpackage from source.

  • Do not include entitlements that are specifically prohibited. At the time of this writing it’s just onecom.apple.security.get-task-allow entitlement.

Store Apple credentials in the keychain

In order to notarize the app, altool must be able to access Apple APIs on your behalf. To secure this access,store your Apple account credentials in the keychain:

Notarize it!

Since altool expects a Zip archive and not a bare .app directory, create a Zip file first and then notarize it:.

Now you need to wait for the notarization results. You’ll get an email from Apple once it’s complete, stating eithera success or failure (and linking to the error logs in this case).

Step 4: Staple the App

In the notarization step above, Apple has created a “ticket”, which is basically a database record which matches yourapp’s signature and saying that it’s been notarized. Your binary has not been modified in any way. When MacOS runsthis app, it will contact Apple servers and ask for a ticket. If such a ticket exists, the app is deemed “notarized”This will happen only once, and then MacOS will cache the results.

If we want to speed up this initial application execution, or if we want to be able to run it when offline, we need to“staple this ticket to the app”, which downloads the ticket and attaches it to your binary. This is as simple as:

This step is optional, but it must be run only after you received an email from Apple stating that the notarizationwas successful.

Python 3.8 Macos Catalina

Step 5: Verify

Now is the good time to verify that everything is in order:

This command uses Gatekeeper directly to assess whether the application is correctly signed and notarized. It shouldreport:

Conclusion

Python Mac Os Catalina Free

While the process outlined above works today, it is certainly cumbersome and has some downsides:

  • The development and build process is much more complicated than the normal MacOS development process with Xcode.Getting new developers onboard would be tricky.

  • It is hard to control the libraries that are being pulled in into your app. If some of the dependencies were builtwith Homebrew, the application probably won’t work on MacOS versions older than the build machine.

Python Macos Catalina

In my opinion, writing MacOS applications in Python is an acceptable route for prototyping, or for building simplein-house tools quickly, and even notarizing the app is perfectly doable.