Has anyone within earshot of this list successfully built a PyQt app with SQL support using py2app? I've been poking and prodding at the problem for a few months now and I'm no closer to a solution to the "cannot move to thread ..." error.

Yes, I think I got this to work recently with Qt3. If I remember correctly, it was due to loading multiple versions of the QtCore library. I think the problem has to do with with Qt plugins not being handled correctly by py2app, and thus the plugins are not being loaded from within in the app bundle. Here's the relevant snippets from the setup.py that I used:

name = "program"

setup(
    name = name,
    ...
    setup_requires=["py2app"],
    options = {
        "py2app": dict(
            argv_emulation=True,
            frameworks=[
                "/path/to/qt/plugins/sqldrivers/libqsqlpsql.dylib",
            ],
        )
    },
    ...
)

if "py2app" in sys.argv:
    # fix the bundle created by py2app
    def do(cmd):
        print " ".join(cmd)
        subprocess.call(cmd)
appdir = os.path.abspath(os.path.join("dist", name + ".app", "Contents"))

    ...

    # move the sql driver where Qt will find it
    plugin_dir = join(appdir, "Resources", "sqldrivers")
    os.makedirs(plugin_dir)
do(["mv", join(appdir, "Frameworks", "libqsqlpsql.dylib"), plugin_dir])


It might be necessary to put the sqldrivers in Contents/MacOS rather than Contents/Resources. I was doing a lot of other strange stuff with this app because I was trying to bundle a bunch of legacy C apps into a stand-alone application that would run on Mac OS.

I'm not familiar with using py2app with macports libraries. But it's a red flag to me that your app is loading libraries from /opt/local/...

dyld: loaded: /opt/local/libexec/qt4-mac/plugins/sqldrivers/ libqsqlpsql.bundle
dyld: loaded: /opt/local/lib/postgresql83/libpq.5.dylib
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtSql.framework/ Versions/4/QtSql dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtCore.framework/ Versions/4/QtCore
dyld: loaded: /opt/local/lib/libz.1.dylib
dyld: loaded: /opt/local/lib/libssl.0.9.8.dylib
dyld: loaded: /opt/local/lib/libcrypto.0.9.8.dylib

Shouldn't those libraries be in your app bundle? I would expect to see them loading from somewhere like /path/to/your/program.app/ Contents/MacOS/../Frameworks

This leads me to believe that you are in fact loading more than one Qt library, which is causing the "cannot move to thread" error, and is probably due to Qt using the wrong plugin(s).

One more thing: I think the plugin resolution logic in Qt changed between Qt3 and Qt4, so the recipe I gave above might not work. You'll need to look that up in the Qt documentation.

~ Daniel



_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to