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

Scott Frankel leknarf at pacbell.net
Tue Sep 22 07:26:31 CEST 2009


Hi all,

In my last post I mentioned that the qt.conf INI file was key to  
fixing the "cannot move to target thread" problem, caused by multiple  
instances of Qt running in the same app.  The following setup.py file  
is my encapsulation of the solution.  This is my first brush with  
py2app, so there may well be some idiosyncrasies in my code.  I'll  
look into contributing a recipe when more of the dust settles.

Thanks
Scott





#-------------------------------------------------------------------------------
# This is a py2app setup.py file, created to build a Qt4 PyQt  
application
# that relies on the PQSQL plugin.  Note that the app links to Qt as  
Frameworks
# and references filenames and directories as installed via macports.
#-------------------------------------------------------------------------------



#-------------------------------------------------------------------------------
# imports
#-------------------------------------------------------------------------------
import sys, os
import subprocess
from setuptools import setup



#-------------------------------------------------------------------------------
# names and dirs
#-------------------------------------------------------------------------------
name         = 'Appname'
APP          = ['Appname.py']
appdir       = os.path.abspath(os.path.join("dist", name + ".app",  
"Contents"))



#-------------------------------------------------------------------------------
# options - setup
#-------------------------------------------------------------------------------
OPTIONS      = {'argv_emulation': True,
				'includes': ['sip', 'PyQt4._qt'],
		
				'excludes': ['PyQt4.QtDesigner', 'PyQt4.QtNetwork',  
'PyQt4.QtOpenGL',
							 'PyQt4.QtScript', 'PyQt4.QtTest', 'PyQt4.QtWebKit',
							 'PyQt4.QtXml', 'PyQt4.phonon'],

				# qt4-mac plugins dir from macports install
				'frameworks': ["/opt/local/libexec/qt4-mac/plugins/sqldrivers/ 
libqsqlpsql.bundle"],
				}

setup(
     app=APP,
     options={'py2app': OPTIONS},
     setup_requires=['py2app'],
)



#-------------------------------------------------------------------------------
# methods
#-------------------------------------------------------------------------------
# wrap subprocess
def doSubproc(cmd):
	print " ".join(cmd)
	subprocess.call(cmd)



#-------------------------------------------------------------------------------
# plugin location
#-------------------------------------------------------------------------------
# copy plugin to the app bundle's plugins dir.  According to Qt docs:
# application.app/Contents/plugins/ is the default location for  
loading Qt plugins
if "py2app" in sys.argv:

	# libqsqlpsql belongs in plugins/sqldrivers
	plugin_dir = os.path.join(appdir, "plugins", "sqldrivers")
	os.makedirs(plugin_dir)
	doSubproc(["cp", os.path.join(appdir, "Frameworks",  
"libqsqlpsql.bundle"), plugin_dir])



#-------------------------------------------------------------------------------
# qt.conf INI file
#-------------------------------------------------------------------------------
# create qt.conf INI file.  For more info,
# http://doc.trolltech.com/4.4/qt-conf.html
iniFilename  = os.path.join(appdir, "Resources", "qt.conf")
iniFile      = open(iniFilename, 'w')

try:
	print "writing %s" % iniFilename
	iniFile.write("[Paths]\nqt_plugpath=plugins")
except IOError:
	print "ERROR: %s not written" % iniFilename

iniFile.close()

# for more info on building Qt apps on Mac OSX, including static  
linking,
# linking to Qt as Frameworks, otool, install_name_tool, and  
dependencies:
# http://doc.trolltech.com/4.4/deployment-mac.html#linking-the-application-to-qt-as-frameworks
	





More information about the Pythonmac-SIG mailing list