A few weeks ago I wrote about DubEval, an open-source app that checks a dubbed video against its original. Back then it was Windows only, and "macOS runs from source" really meant "macOS doesn't". Last week the Mac version shipped: signed with a Developer ID, notarized, and able to update itself.
The app is an Electron window around a Python server: about 560 MB, with Python 3.14, Whisper (CTranslate2), ONNX Runtime, OpenCV and a few models inside. Electron apps get signed every day. Electron apps with a whole Python inside are rarer, and most of what broke came from that Python. Here's what broke, in the order I hit it.
1. python.org's Python can't go inside an app
The official macOS installer puts Python in /Library/Frameworks and expects it to stay there. Copy it into an .app and it still looks for itself at the old path.
Fix: python-build-standalone, a relocatable CPython (the one uv uses). I pin one release and its SHA-256 in the build script, so every build starts from exactly the same bytes:
MAC_PYTHON = {
"arm64": ("https://github.com/astral-sh/python-build-standalone/releases/download/20261110/"
"cpython-3.14.10%2B20261110-aarch64-apple-darwin-install_only_stripped.tar.gz",
"f15ec3d15460dd66c2eb88639b152cd9040e7d1ece11e38bf89e8f53f0171e02"),
}
2. Python writes into its own folder, and that breaks the signature
A signed app is sealed: change one file inside it and the signature no longer matches. Python changes files all the time: the first import of a module writes a .pyc next to it, inside the bundle.
Fix: compile every .py file at build time and start Python with -B, so it never writes bytecode. The .pyc files use unchecked-hash invalidation, so they stay valid whatever happens to file timestamps on the way to the user:
python -m compileall -q -j 0 --invalidation-mode unchecked-hash <the bundled Python's folders>
numba was the sneaky one. It caches compiled machine code next to the library by default, and that cache depends on the CPU it was built on, so it can't be shipped either. NUMBA_CACHE_DIR now points at the app's data folder. The cost: the first evaluation on a new Mac is about 10 seconds slower.
3. electron-builder tried to sign thousands of data files
electron-builder signs every file in the bundle that isn't plain text, one by one. A Python environment with models has thousands of those: model weights, .npz data, compiled resources. The first build ran for ages and then stopped on a file that happened to be read-only.
Fix: keep electron-builder off the Python and model folders (signIgnore) and sign only what needs a signature myself in an afterPack hook: every Mach-O file, found by its first bytes rather than by file name. A Mac program often has no extension, and a library can be named anything.
One trap: a "fat" (universal) Mach-O file starts with 0xCAFEBABE, and so does every Java .class file. The next 4 bytes tell them apart. A universal file counts its architectures there, a class file has its version (45 or more):
if (head.subarray(0, 4).equals(MACHO_FAT)) {
if (head.readUInt32BE(4) >= 45) return null; // a Java class file, not a Mac binary
at = head.readUInt32BE(16); // jump to the first architecture's header
...
}
That found 367 programs and libraries. Each gets codesign --force --timestamp --options runtime, and the programs also get the entitlements.
4. The hardened runtime needs only two exceptions
Notarization requires the hardened runtime, which blocks, among other things, writing machine code at run time and loading libraries signed by someone else. I expected a long entitlements file. It came down to two keys:
<key>com.apple.security.cs.allow-jit</key> <!-- V8, and numba's compiled code -->
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key> <!-- Python's ctypes callbacks -->
<true/>
No disable-library-validation. Because step 3 signs every library in the bundle with the same Developer ID, nothing needs to load another team's code.
5. The keychain and I had a disagreement
Three separate surprises, all from the same place:
- "0 valid identities found". The Developer ID certificate was in the keychain, but its intermediate (Apple's "Developer ID Certification Authority", G2) wasn't, so macOS couldn't build the chain and ignored the certificate. Installing the intermediate fixed it.
-
Signing in parallel failed. The first time
codesignuses the private key, macOS asks "allow access?". I was signing 8 files at once, so 8 dialogs appeared and the build failed. Now the first file is signed alone (click Always Allow once), then the rest 8 at a time. -
Over SSH:
errSecInternalComponent. I drive the Mac from my Windows PC over SSH. An SSH session can't show that keychain dialog, socodesignjust fails. Signed builds run in the Mac's own Terminal. Unsigned test builds still work over SSH.
After that, notarization itself was the easy part: APPLE_KEYCHAIN_PROFILE with credentials saved by xcrun notarytool store-credentials, and about 10 minutes of waiting for Apple.
6. Auto-update wants the zip, not the dmg
Users download the .dmg, but electron-updater (Squirrel.Mac underneath) updates from the .zip and a latest-mac.yml next to it. Forget either in a GitHub release and every installed copy's update check fails. It also installs only an update signed with the same Developer ID, so a Mac release can never go out unsigned again.
A small thing that helped: the .dmg has no version in its name (DubEval-Mac.dmg), so /releases/latest/download/DubEval-Mac.dmg always points at the newest one, and the website never needs editing.
(Windows has its own version of this. Our installer is signed after it's built, which changes its bytes, so the SHA-512 in latest.yml and the .blockmap have to be rebuilt from the signed file. Ship the build's latest.yml and every installed app refuses the update.)
7. Then it was just slow, for two reasons
The first real evaluation on an M2 Pro took 16 minutes for a 1-minute clip, on a machine that should do it in 3.
The Mac fell asleep. pmset -g log showed 766 seconds of sleep in the middle of the run. The app was working flat out, but a background job isn't "user activity", so the idle timer just ran out. The fix is macOS's own caffeinate, tied to the server's process so it ends when the server does:
subprocess.Popen(["/usr/bin/caffeinate", "-i", "-w", str(os.getpid())])
(Windows needs the same thing: SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED).)
Speech recognition used the wrong cores. CTranslate2's default thread count includes the efficiency cores, and on Apple silicon those slow the whole batch down. Asking macOS for the performance cores only:
subprocess.run(["/usr/sbin/sysctl", "-n", "hw.perflevel0.physicalcpu"], capture_output=True, text=True)
took a whole evaluation from 217 to 169 seconds, with the same verdict. On my Intel Core Ultra 7 laptop the same change did nothing, so it's macOS only. Both fixes ship in the next version (0.1.8).
What changed since the first post
- Windows installer is signed now, so SmartScreen no longer warns.
- Mac app: Apple silicon, macOS 14 or later.
- Lip sync counts in the verdict when you install its optional model (StableSyncNet).
- The local translation checker is now Gemma 4 12B (through a bundled Ollama). In my first post the local model found 4 of 23 planted translation mistakes. Gemma 4 12B caught 28 of 28 on Windows and on the Mac. That's planted mistakes on 8 dubs, one run each, not yet compared with a human reviewer, so take it as promising, not proven.
Try it
- Download for Mac or Windows
-
Source on GitHub (AGPL-3.0; the build script and
after-pack.jsare intools/anddesktop/if you're packaging your own Python app)
Disclosure: I work at ESTsoft, which makes Perso AI (an AI dubbing service). DubEval is free and works with dubs from any service or from voice actors.
If you've shipped a Python runtime inside a Mac app another way (PyInstaller, Briefcase, py2app), I'd like to hear what broke for you.
Top comments (0)