[Pythonmac-SIG] py2app cannot move to target thread error

Scott Frankel leknarf at pacbell.net
Fri Sep 18 07:52:27 CEST 2009


Hi Daniel,

Thanks for the info and sample code!  I've now got libqsqlpsql.bundle  
copying to the app bundle's frameworks dir.

Reading http://doc.trolltech.com/4.4/deployment-mac.html#linking-the-application-to-qt-as-frameworks 
, I'm knee deep in otool and install_name_tool.  I had no idea I had  
to wrestle with this for a Python app.

I'll post back to the list once I've got things working.  At least the  
train is rolling again!  Thanks for your help.

Scott



On Sep 17, 2009, at 10:55 AM, Daniel Miller wrote:

>> 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
>
>
>



More information about the Pythonmac-SIG mailing list