gregneagle/relocatable-python

Is there a way to bypass usage of the launcher (Python.app)?

Closed this issue · 2 comments

Context

I'm bundling a relocatable-python in my app bundle that uses pyobjc and am running into an issue producing notifications.

The notification code uses NSUserNotification from objc. Notifications are shown as coming from the Python.app launcher that's embedded in Python.framework/Versions/Current/Resources/Python.app. (This includes the python launcher icon and the software name "python".)

Notification with python and python launcher icon

Before using relocatable-python, I leveraged macholib in order to make an installed version of Python relocatable, and it didn't include the Python.app launcher at all.


Ask

Is it possible to somehow run python without the Python launcher?


Versions

I'm bundling python3.8 and running on macOS Big Sur


Additional info

Right now I'm launching the program using Python.framework/Versions/Current/bin/python, and if I delete the Python launcher in Resources, I get this error:

$ ./Frameworks/Python.framework/Versions/Current/bin/python ↵
python3.8: posix_spawn: /Applications/MyApp.app/Contents/Frameworks/Python.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python: Undefined error: 0

which indicates to me that the bin files also leverage the launcher.


Considerations

I realize this question may be beyond the scope of this project, but was hoping for guidance in case this is something that you've seen before or someone else has solved.

I don't know the answer to your questions. It would be a good question for the maintainers of the macOS builds of the official Python.org releases.

I managed to workaround this issue.

  1. Move the launcher binary out of Python.app
  2. Fix its rpath to support its new home
  3. Remove the remaining codesign metadata (particularly the identifier): /usr/bin/codesign -s - --deep --force
  4. Add a PList next to the binary that just contains our bundle identifier