[PySide] cxfreeze and PySide 1.2.0

Joel B. Mohler jmohler at gamry.com
Wed Jul 10 18:36:06 CEST 2013

On 7/9/2013 11:20 AM, John Ehresman wrote:
> On 7/9/13 11:06 AM, Joel B. Mohler wrote:
>> I have tried commenting out the _setupQtDirectories in __init__.py. It
>> then crashes (ala segfault) on the import of QtCore.  I can't think of
>> anything that makes sense explaining that crash since it works fine
>> unfrozen and the normal cxfreeze failure mode is to have some missing
>> dll or module ... not crashes.
> It would be nice for someone to try this in a debug build and hopefull 
> identify where it's segfaulting.  Even if it won't work without a 
> qt.conf, it shouldn't segfault.

Aha, this has been an interesting journey to get this all compiled in 
debug.  I have found the problem.

         Shiboken::AutoDecRef atexit(Shiboken::Module::import("atexit"));
         Shiboken::AutoDecRef regFunc(PyObject_GetAttrString(atexit, 

This C-level module import in qtcore_module_wrapper.cpp imports python 
module atexit, but it fails and so the second line crashes because 
atexit is null.  So, easy fix is to include "--include-modules=atexit" 
in the cxfreeze command line.

So, what is the correct fix?  I think that import in sbkmodule.cpp does 
right to set the PyErr, but the calling code copied above originating 
from typesystem_core_common.xml (I think?) doesn't check PyErr_Occurred 
and I don't know how the error should propagate in the abstract 
conditions of typesystem_core_common.xml.

With that knowledge, then I suggest the following is a cxfreeze friendly 
implementation of __file__ access appropriate in this context:

diff --git a/PySide/_utils.py.in b/PySide/_utils.py.in
index fb2d25e..f82ce65 100644
--- a/PySide/_utils.py.in
+++ b/PySide/_utils.py.in
@@ -84,8 +84,10 @@ if sys.platform == 'win32':
          return path

      def get_pyside_dir():
-        return 
+        from . import QtCore
+        return 

      def get_pyside_dir():
-        return os.path.abspath(os.path.dirname(__file__))
+        from . import QtCore
+        return os.path.abspath(os.path.dirname(QtCore.__file__))

I would be happy to hear opinions on these topics.


More information about the PySide mailing list