[PyQt] Next Releases

Phil Thompson phil at riverbankcomputing.com
Tue Sep 9 00:14:50 BST 2014


On 08/09/2014 7:16 pm, Georg Brandl wrote:
> On 09/08/2014 07:29 PM, Georg Brandl wrote:
> 
>>>>          // Make sure the interpreter is loaded and initialised.  
>>>> Leave
>>>> this as
>>>>          // late as possible.
>>>> -        if (!Py_IsInitialized())
>>>> -        {
>>>> -            QLibrary library(PYTHON_LIB);
>>>> -
>>>> -            
>>>> library.setLoadHints(QLibrary::ExportExternalSymbolsHint);
>>>> -
>>>> -            if (!library.load())
>>>> -                return;
>>>> -
>>>> -            Py_Initialize();
>>>> -        }
>>>> +        Py_Initialize();
>>>> 
>>>>          // Make sure we have sys.path.
>>>>          if (!sys_path)
>>> 
>>> The reason why that code was removed was because I couldn't see how 
>>> it
>>> was having any affect - if Py_Initialized() could be called then the
>>> library must already be loaded. However if it fixes your problem then
>>> I'll revert it. The value of PYTHON_LIB should be
>>> "/path/to/libpython2.7".
>> 
>> I've just made a new build with the change reverted (with a hardcoded 
>> path
>> in place of PYTHON_LIB) and can confirm that it fixes the issue.
>> 
>> I won't pretend to understand it either...
> 
> Hmm, as far as I can understand the thing after looking into "man 
> dlopen" a
> bit: the designer loads its plugins with QPluginLoader, which by 
> default
> doesn't use the RTLD_GLOBAL flag (i.e. ExportExternalSymbolsHint in Qt
> parlance).  The libpyqt4.so designer plugin is loaded, and since it is
> dynamically linked with libpython2.7, that one gets loaded too, but is 
> not
> available for global symbol resolution.
> 
> Now the sip.so extension is *not* linked with libpython2.7 (like all 
> Python
> extension modules), so when it gets loaded with dlopen (by Python), the 
> linker
> can't find the symbols exported by the Python library.  The old code 
> basically
> enforced Python symbols to be global and available for resolution by 
> the linker.
> 
> Hope that makes at least a bit of sense...

...so a different implementation might have libpyqt4.so *not* linked 
against libpython2.7 and access all the required functions by pointers 
returned by QLibrary::resolve().

On the other hand, if I ignored the value returned by load() (in the 
original code) then it might work with both a dynamic and a static 
Python library.

Phil


More information about the PyQt mailing list