mac app from a python script?

Dan Stromberg drsalists at gmail.com
Wed Jan 26 00:17:14 EST 2022


On Tue, Jan 25, 2022 at 6:41 PM Dan Stromberg <drsalists at gmail.com> wrote:

>
> On Tue, Jan 25, 2022 at 2:23 PM Barry <barry at barrys-emacs.org> wrote:
>
>>
>> On 25 Jan 2022, at 02:56, Dan Stromberg <drsalists at gmail.com> wrote:
>>
>> 
>>
>> On Sun, Jan 23, 2022 at 1:37 PM Barry <barry at barrys-emacs.org> wrote:
>>
>>>
>>> I do not have experience with great, but you might try pyinstaller.
>>> I use it to make a PyQt Mac app successfully.
>>>
>>> It’s command line plus setup script.
>>>
>>
>> I wound up doing:
>> 1) pyinstaller, as normal, but this created a broken all-encompassing
>> binary of my script.  At least it gave me the metadata I needed though.
>>
>>
>> You mean it created a .app bundle?
>>
>> That is the way that macOS makes it trivia to install apps
>> Just by drag and drop in /Applications.
>>
>
> Yes, it created an hcm.app for me.  But the executable it created didn't
> work.  Hence the hack.
>

More specifically:
$ /Applications/hcm.app/Contents/MacOS/hcm --gui
cmd output started 2022 Tue Jan 25 09:00:33 PM PST
Traceback (most recent call last):
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 146, in
<module>
    _run()
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 129, in
_run
    exec(compile(source, path, "exec"), globals(), globals())
  File "/Applications/hcm.app/Contents/Resources/hcm.py", line 1950, in
<module>
    import gi
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in
_load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "gi/__init__.pyc", line 40, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in
_load_backward_compatible
  File "<frozen zipimport>", line 259, in load_module
  File "gi/_gi.pyc", line 14, in <module>
  File "gi/_gi.pyc", line 10, in __load
  File "imp.pyc", line 342, in load_dynamic
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 627, in
_load_backward_compatible
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 36, in
load_module
    return imp.load_module(
  File "imp.pyc", line 244, in load_module
  File "imp.pyc", line 216, in load_package
  File "<frozen importlib._bootstrap>", line 710, in _load
AttributeError: 'NoneType' object has no attribute 'name'
2022-01-25 21:00:34.576 hcm[62695:1322031] hcm Error
^C^\Quit: 3
above cmd output done    2022 Tue Jan 25 09:00:42 PM PST
dstromberg at Daniels-Mini:~/src/home-svn/hcm/trunk x86_64-apple-darwin20.6.0
61933

$ file /Applications/hcm.app/Contents/MacOS/hcm
cmd output started 2022 Tue Jan 25 09:00:54 PM PST
/Applications/hcm.app/Contents/MacOS/hcm: Mach-O 64-bit executable x86_64

But if I replace /Applications/hcm.app/Contents/MacOS/hcm with a symlink to
a wrapper shell script, hcm runs fine from the Applications menu.

It seems that gi.repository.Gtk applications are not packaged correctly by
pyinstaller and py2app.  Some Python modules require a little assistance to
be packaged up into a Mach-O executable neatly by such tools.  But it's
just not that important to me to have a Mach-O of my app.


More information about the Python-list mailing list