I get an error message when running app created by py2app. Apparently, a library is placed where it can't be found. If its's placed so it can be found, the app segfaults.
Here's an mwe:
mwe:
from PySide6.QtWidgets import QApplication, QFileDialog, QPushButton, QVBoxLayout, QWidget
import json
from datetime import date
import sys
class FileDialogDemo(QWidget):
def __init__(self):
super(FileDialogDemo, self).__init__()
layout = QVBoxLayout()
self.btn = QPushButton("Velg Excel-fil")
self.btn.clicked.connect(self.loadFileDialog)
layout.addWidget(self.btn)
self.setLayout(layout)
self.setWindowTitle("Last opp Excel-dokument")
def loadFileDialog(self):
filepath, _ = QFileDialog.getOpenFileName(self, "Åpne Excel-fil", "", "Excel Files (*.xls *.xlsx)")
if filepath:
print(f"Du valgte filen: {filepath}")
with open("config.json", "w") as f:
json.dump({"filepath": filepath}, f)
self.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = FileDialogDemo()
demo.show()
sys.exit(app.exec_())
$python3.9 setup.py py2app
$./dist/mwe.app/Contents/MacOS/mwe
raises
Traceback (most recent call last):
File "/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/__boot__.py", line 161, in <module>
_run()
File "/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/__boot__.py", line 84, in _run
exec(compile(source, path, "exec"), globals(), globals())
File "/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/mwe.py", line 1, in <module>
from PySide6.QtWidgets import QApplication, QFileDialog, QPushButton, QVBoxLayout, QWidget
ImportError: dlopen(/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/QtWidgets.abi3.so, 0x0002): Library not loaded: @rpath/libshiboken6.abi3.6.5.dylib
Referenced from: <2A2824C7-0077-3109-9944-32020F57621C> /Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/QtWidgets.abi3.so
Reason: tried: '/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/libshiboken6.abi3.6.5.dylib' (no such file), '/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/Qt/lib/libshiboken6.abi3.6.5.dylib' (no such file), '/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/libshiboken6.abi3.6.5.dylib' (no such file), '/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Resources/lib/python3.9/PySide6/Qt/lib/libshiboken6.abi3.6.5.dylib' (no such file), '/Users/roffe/Documents/prosjekter/mwe.py/dist/mwe.app/Contents/Frameworks/Python.framework/Versions/3.9/../../../../../../../lib/libshiboken6.abi3.6.5.dylib' (no such file), '/usr/local/lib/libshiboken6.abi3.6.5.dylib' (no such file), '/usr/lib/libshiboken6.abi3.6.5.dylib' (no such file, not in dyld cache)
2023-09-02 19:26:41.284 mwe[99161:948342] Launch error
2023-09-02 19:26:41.285 mwe[99161:948342] Launch error
See the py2app website for debugging launch issues
setup.py is
""" This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = [ 'mwe.py' ]
DATA_FILES = [ ]
OPTIONS = {
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Moving library to a place where it is found raises an exception and the process terminates.
Setup is python 3.9, MacBook Pro running m1. Same issue with python 3.10 and 3.11.