I'm attempting to bundle up a test program (an "hello world") as a macOS app using py2app.
The error I get is:
/Applications/hello.app/Contents/MacOS/hello
Traceback (most recent call last):
File "/Applications/hello.app/Contents/Resources/__boot__.py", line 101, in <module>
_run()
File "/Applications/hello.app/Contents/Resources/__boot__.py", line 84, in _run
exec(compile(source, path, "exec"), globals(), globals())
File "/Applications/hello.app/Contents/Resources/hello.py", line 5, in <module>
import gi
File "<frozen zipimport>", line 259, in load_module
File "gi/__init__.pyc", line 40, in <module>
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
ModuleNotFoundError: No module named 'gi._error'
2021-06-08 10:19:34.605 hello[41423:3966514] hello Error
make: *** [go] Error 255
The program, which runs fine outside of py2app, is:
$ cat hello.py
cmd output started 2021 Tue Jun 08 10:20:44 AM PDT
#!/usr/bin/env python3
"""Just say hi."""
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk # noqa
window = Gtk.Window(title="Title")
button = Gtk.Button(label='Hello World!')
button.show()
button.connect("clicked", Gtk.main_quit)
window.add(button)
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()
My setup.py looks like:
$ cat setup.py
cmd output started 2021 Tue Jun 08 10:21:27 AM PDT
"""
This is a setup.py script derived from https://stackoverflow.com/questions/5608080/how-to-specify-py2app-icon .
Usage:
python3 setup.py py2app
"""
from setuptools import setup
app = ['hello.py']
options = {
'iconfile': 'icon/hello.png',
}
setup(
app=app,
options={'py2app': options},
setup_requires=['py2app'],
)
And here's the Makefile I've been using, which includes creation of the icon file:
$ cat Makefile
cmd output started 2021 Tue Jun 08 10:22:25 AM PDT
go: clean
./hello.py
pbmtext 'hello!' | pnmtopng > icon/hello.png
python3 setup.py py2app
(cd dist && tar cflS - hello.app) | (cd /Applications && tar xvfp -)
/Applications/hello.app/Contents/MacOS/hello
clean:
rm -rf build dist
rm -f icon/hello.png
I'm using homebrew python 3.9.5 and py2app==0.24 on macOS Big Sur (11.4). py2app was installed with pip.
I suspect this situation calls for a "recipe", but I don't see one for PyGObject in the py2app documentation.
I've googled about this for hours, but no luck.
Does anyone have any suggestions?
Thanks!