How to solve "Could not load the Qt platform plugin "cocoa" in "" even though it was found."
-
@JimboNiss hi and welcome to devnet,
What exactly do you have in your py2app folder ?
Do you have the QDbus framework in your app bundle ?wrote on 28 Jan 2022, 19:46 last edited by@SGaist, not sure what you are asking, but I just updated py2app via pip3, as a test. Didn't help. Here is my setup.py for it:
"""
This is a setup.py script generated by py2appletUsage:
python setup.py py2app
"""from setuptools import setup
APP = ['englauncher.py']
DATA_FILES = [('', ['applescript'])]
#DATA_FILES = []
OPTIONS = {
'iconfile': 'icon_SEO.icns',
'packages': ['cffi']
}setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)The QtDBus directory is in both /Applications/<app> and the py2app created ./disk/<app>...
Jims-MacBook-Pro:englauncher3 $ sudo find /Applications -name "QtDBus"
Password:
/Applications/englauncher.app/Contents/Resources/lib/python3.9/PyQt5/bindings/QtDBus
/Applications/englauncher.app/Contents/Resources/lib/python3.9/PyQt5/Qt5/lib/QtDBus.framework/Versions/5/QtDBus
Jims-MacBook-Pro:englauncher3 $ sudo find ./dist -name "QtDBus"
./dist/englauncher.app/Contents/Resources/lib/python3.9/PyQt5/Qt5/lib/QtDBus.framework/Versions/5/QtDBus
./dist/englauncher.app/Contents/Resources/lib/python3.9/PyQt5/bindings/QtDBus -
Can you check the rpath values of the executable ?
See here for more information about it.
-
wrote on 28 Jan 2022, 21:55 last edited by
@SGaist said in How to solve "Could not load the Qt platform plugin "cocoa" in "" even though it was found.":
here
Ok, I was able to locate the rpath...
Jims-MacBook-Pro:englauncher3 $ otool -L ./dist/englauncher.app/Contents/plugins/platforms/libqcocoa.dylib |grep -i qtdbus
@rpath/QtDBus.framework/Versions/5/QtDBus (compatibility version 5.15.0, current version 5.15.2)Jims-MacBook-Pro:englauncher3 $ otool -L /Applications/englauncher.app/Contents/plugins/platforms/libqcocoa.dylib |grep -i qtdbus
@rpath/QtDBus.framework/Versions/5/QtDBus (compatibility version 5.15.0, current version 5.15.2)https://stackoverflow.com/questions/12521802/print-rpath-of-an-executable-on-macos/12522096#125220
Jims-MacBook-Pro:englauncher3 $ otool -l dist/englauncher.app/Contents/MacOS/englauncher | grep RPATH -A2
cmd LC_RPATH
cmdsize 48
path @executable_path/../Frameworks (offset 12)
Jims-MacBook-Pro:englauncher3 $ otool -l dist/englauncher.app/Contents/MacOS/englauncher
Jims-MacBook-Pro:englauncher3 $ otool -l /Applications/englauncher.app/Contents/MacOS/englauncher | grep RPATH -A2
cmd LC_RPATH
cmdsize 48
path @executable_path/../Frameworks (offset 12)Jims-MacBook-Pro:englauncher3 $ ls dist/englauncher.app/Contents/Frameworks
Python.framework libcrypto.1.1.dylib liblzma.5.dylib libmpdec.2.5.1.dylib libmpdec.3.dylib libssl.1.1.dylib
Jims-MacBook-Pro:englauncher3 $ ls /Applications/englauncher.app/Contents/Frameworks
Python.framework libcrypto.1.1.dylib liblzma.5.dylib libmpdec.2.5.1.dylib libmpdec.3.dylib libssl.1.1.dylibWhat's odd is I can run the application from the dist directory just fine:
./dist/englauncher.app/Contents/MacOS/englauncherBut, I get the error when running it from /Applications:
/Applications/englauncher.app/Contents/MacOS/englauncherI copied the application from ./dist to /Applications, so they should be the same.
-
wrote on 28 Jan 2022, 23:02 last edited by
HI, just guessing but maybe your app is picking up the QtDBus dylib from another place outside of your englauncher.app directory (and using relative paths).
To check, could you launch your app from the dist directory (i.e. where it runs successfully) and then open a Terminal and type
lsof -c englauncher
this will show what dlls/dylibs are loaded (and most importantly their paths). -
HI, just guessing but maybe your app is picking up the QtDBus dylib from another place outside of your englauncher.app directory (and using relative paths).
To check, could you launch your app from the dist directory (i.e. where it runs successfully) and then open a Terminal and type
lsof -c englauncher
this will show what dlls/dylibs are loaded (and most importantly their paths).wrote on 28 Jan 2022, 23:09 last edited by@hskoglund, the process doesn't keep running, so not sure I can run lsof on it.
Another thing I tried is completely uninstalling python3 from brew repository, and reinstalling it directly from python3, using Mac disk image. Had to reinstall my pip libraries, and got the same exact issue.
I'm at my wits end with this, and think it's a Big Sur issue, though can't prove it.
-
wrote on 29 Jan 2022, 09:37 last edited by
Hi, one way stop your app from exiting, you could try showing a message box, for example like this:
... app = QApplication([]) alert = QMessageBox() alert.setText('Click me when lsof -c is done') alert.exec() ...
then you should have time to do a
lsof -c englauncher
-
Hi, one way stop your app from exiting, you could try showing a message box, for example like this:
... app = QApplication([]) alert = QMessageBox() alert.setText('Click me when lsof -c is done') alert.exec() ...
then you should have time to do a
lsof -c englauncher
wrote on 31 Jan 2022, 15:59 last edited by@hskoglund, that didn't help, as it's not even able to load the Qt libraries. I even created a simple test app with your code, and while I can run it from ./dist/testapp, as soon as I copy it to /Applications, it fails loading the libraries in the same way.
-
wrote on 31 Jan 2022, 16:07 last edited by
Ok, please run that simple test app again from /dist/testapp, and while that QMessageBox is displayed, start a Terminal and type
lsof -c testapp
-
wrote on 10 Mar 2022, 11:31 last edited by
i have the same question,wait answer,please
-
wrote on 14 Mar 2022, 01:14 last edited by
no answer?please help
-
wrote on 14 Mar 2022, 04:27 last edited by
Hi, please create a new forum post and describe your problem, what version of Python and MacOS you have etc.
-
Hi, please create a new forum post and describe your problem, what version of Python and MacOS you have etc.
wrote on 14 Mar 2022, 06:03 last edited by@hskoglund ok,thank u
-
wrote on 22 Mar 2022, 18:15 last edited by
I fixed this on my machine by requiring py2app version 0.25
setup_requires=['py2app==0.25']
in the setup.pyThis problem is described in https://github.com/ronaldoussoren/py2app/issues/380 and there's already a patch. Just don't use 0.26 and 0.27.