PyQt4: I hate you
No, that’s not true… if I didn’t love Qt Designer and python so much, I wouldn’t tolerate PyQt, so I must secretly love PyQt. UGH BAD LOVE. And py2app is like the foul-smelling friend of PyQt that comes around once a week to get both of them drunk and loud at 3:00 AM.
So I spent the entire morning checking, tweaking and re-checking my import statements, my .profile, my paths, my app, my resources, my plugins — all because my library source wasn’t making it into my py2app-generated app. You know — these source files that are imported in every one of my python modules? Yeah, not there. Didn’t make the cut. Sorry.
I checked my notes from the LAST time I went through this, with no results. I Googled. I checked forums. I googled again. I emacsed. I sourced. I logged and moved and copied and pasted.
And then a little after lunch a tiny voice said “Why don’t you use the –no-strip flag?”
That voice was smart. A little bit of this action got me a working app:
python setup.py py2app –include sip –no-strip
Yeah, at 44 Mb it’s kind of fatty. But you know what I’m gonna do about that. NOTHING.
FOR A WHILE.
But NOW… oh ho ho NOW my jpeg-based thumbnails aren’t showing up. You wanna know why? Because apparently Qt’s jpeg support is a plugin. The last time I had to tangle with a plugin was phonon, and that worked OK until PyQt’s failure to wrap an obscure phonon object caused a persistent and deadly threading error. How did I get around that, you ask? I DIDN’T. I used the built-in python modules wave and pyaudio and rewrote what I had been getting from phonon. Don’t talk to me about phonon. Phonon is dead to me!
Anyhoo. Such is technology.
Time to copy over some plugins…
**Update 5:07 PM**
I had been getting this message when my application attempted to load a jpeg-based QPixmap:
On Mac OS X, you might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
QObject::moveToThread: Current thread (0x13b11f40) is not the object’s thread (0x1e8760).
I found this. All I did was add a blank qt.conf to the myApp.app/Contents/Resources folder, and this error ceased. You’ll notice that’s all the bug-tracker describes — how to get the error to go away — not how to get the imageformats plugin to work.
I am still trying all sorts of different things to get my application to pick up the imageformats’ jpeg plugin… Will update…
Update 3/5
Nope. Couldn’t make the plugin happen. Fortunately — VERY fortunately — I had the option and ability to convert and store the JPEGs as PNGs on-the-fly, so I can use PNGs, which are native to Qt and work ju-u-u-ust fine when all apped up.
Someday I’ll be able to make an apped-up Qt plugin work, but it hasn’t happened yet.
Update 9/1
After much research and experimentation I came to this conclusion about trying to use plugins in a py2app-generated PyQt app: I can’t. But there’s a workaround.
Yes, thank you very much for posting the empty qt.conf trick. Very strange and wonderful at the same time.
Many thanks for the note on adding a blank qt.conf, you saved me many hours of googling!
After hours of stumbling around with the same issue, I’d like to share the solution that worked for me on windows vista:
using python2.6
copy the following directory into your dist directory generated by py2exe:
C:\Python26\Lib\site-packages\PyQt4\plugins\imageformats
I just dropped the imageformats directory directly into my dist directory, without any further modifications to qt.conf or anything like that. I haven’t tried it, but this may work for phonon as well.
enjoy!
Ciao,
yesterday, I tried on Tiger:
it’s work!
Tory have you tried?
Ruggero
Ciao,
Lets suppose you have your application MyApp.app
In MyApp.app/Contents/plugins/imageformats/
put the libraries:
libqjpeg.dylib
libqgif.dylib
In MyApp.app/Contents/resources/
put qt.conf that contains:
[Paths]
Prefix = .
Binaries = .
Ok, on my machine (Leopard) all works.
Sorry for the bad English.
Ruggero
Ruggero
Interesting! I will have to try this. THANK YOU!
THANK YOU! I hope I was half as helpful as other people were to me. Also — note that running macdeployqt on your app will do some nice repairs on it, including adding the qt.conf file (so you don’t have to do it manually every time). macdeployqt comes with Qt 4.5, and there is more information on it here.
wowies, the qt.conf tip was a total godsend — i spent weeks trying to decipher this, you saved my month!
daby – But that is because it has to stay consistent with the “Qt is Qt, any platform” feature!
my wish is for pyqt to be more pythonic. i mean in wxpython the c++ syntax is ‘almost’ invisible, in pyqt its everywhere.
I just loooooove it when you speak nerd…