Native python module in Catalina

Hi guys, I've been working on a native Python module for a Blender addon. The Python module is written in Rust, and it runs inside the python interpreter bundled with Blender. The module imports fine if I start Blender from the command line, but if I start it from the icon it crashes immediately.


Apparently this is because of the new Gatekeeper requirements in Catalina, where binaries have to be notarized. My question is: how do I notarize a python module? It's a .so file. There's also the issue that it runs inside Blender, does that change anything?


Thanks!

Replies

I suggest doing some detailed debugging on the issue before assuming it is related to notarization. There are a number of things that can go wrong trying to load a dynamic library. Considering that you are talking about an embedded python inside another app being launched only in one context means that you really need to clarify exactly what is going on. There are many, many things that could affect the loading of this library.

Apparently this is because of the new Gatekeeper requirements in Catalina, where binaries have to be notarized.

I’m with john daniel on this one: This is unlikely to be related to Gatekeeper or notarisation. Specifically:

  • Gatekeeper only applies if the program is quarantined, and that’s clearly not the case here (because you’re building it locally).

  • On older systems Gatekeeper only applied to apps, but on 10.15 we started applying Gatekeeper to all programs, including command-line tools run from Terminal. If this were a Gatekeeper problem, you’d see problems regardless of how you start the app.

My question is: how do I notarize a python module? It's a .so file.

On the Mac an

.so
file is typically a shared library (
MH_DYLIB
) and these can be notarised. However, you only need to worry about notarisation when you get to the point of distributing your product such that users download it and it ends up quarantined.

There are many different reasons why an app might crash when run from Terminal but not when launched from the Finder, or vice versa. I’ve recently been discussing this with another developer on this thread. It’s unlikely that your problem has the same underlying cause, but it should give you some insight into how to approach this.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi John,


Thanks for replying. Blender supports addons (or plugins) written in Python. It comes with it's own Python interpreter bundled that runs inside Blender. It loads them and imports all their modules when it starts. If I run it from the command line It can import my .so file, but when I run it from the icon (desktop/dock) I get a crash with this backtrace:


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff6a0a97fa __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff6a16bbc1 pthread_kill + 432
2 libsystem_c.dylib 0x00007fff6a030ab6 __abort + 139
3 libsystem_c.dylib 0x00007fff6a030a2b abort + 135
4 pangu.so 0x0000000134e33939 std::sys::unix::abort_internal::h6717f22b70679bc4 + 9
5 pangu.so 0x0000000134e31c70 std::sys_common::util::abort::h1dd17fd3c0d65cf7 + 80
6 pangu.so 0x0000000134e32c53 rust_panic + 99
7 pangu.so 0x0000000134e32bed std::panicking::rust_panic_with_hook::h4a09e69cd55e5140 + 589
8 pangu.so 0x0000000134e32689 rust_begin_unwind + 169
9 pangu.so 0x0000000134e5162c core::panicking::panic_fmt::h504df364bc4c5c34 + 44
10 pangu.so 0x0000000134e51709 core::result::unwrap_failed::h6f0ff48485ebd7be + 121
11 pangu.so 0x0000000134e08a6a pangu::pangu::hf0851a193c56c6ff + 218
12 pangu.so 0x0000000134e02d83 pyo3::derive_utils::make_module::h9760a9aa3677d944 + 147
13 org.blenderfoundation.blender 0x000000010ec53d83 _PyImport_LoadDynamicModuleWithSpec + 579
14 org.blenderfoundation.blender 0x000000010ec537d3 _imp_create_dynamic + 355
15 org.blenderfoundation.blender 0x000000010eb5cfcd _PyMethodDef_RawFastCallDict + 605
16 org.blenderfoundation.blender 0x000000010eb5ca78 PyCFunction_Call + 200


Pangu is my module, PyO3 is the rust binding for Python. Blender's python version is 3.7.4 and it's the same in both cases.

Hey Eskimo, thanks for replying. That was a useful thread none the less. I didn't know apps where launched in a different context, or via a different system. The only things I can think of right now is either the Rust-Python bindings having a bug (unlikely) or the logger that prints to stdout causing this problem. I'll see if I can run Blender inside lldb

If you are having problems with funky 3rd party software, it would be best to contact the developer support for said software.

This "funky 3rd party software" runs perfectly fine on every other platform, I even got it to build inside a docker image. MacOS is literally the only problem I have now.

macOS is strictly incidental to your code. You are using Blender, Python, and Rust. But those are all open-source projects, aren't they? That means that this is the only support you have. You are probably making some assumptions about the current directory or the current environment.