[External] Re: RuntimeError: the PyQt5.QtCore module failed to register with the sip module

Phil Thompson phil at riverbankcomputing.com
Fri Jul 22 09:59:44 BST 2022


On 21/07/2022 17:28, Edward A. Pier wrote:
> Thank you for your response. That makes sense that
> PyImport_ImportModule would call sip_api_export_module. That does not
> appear to be happening, though. When I add print statements to trace
> the code, I see PyImport_ImportModule getting called, then the code
> proceeds to the search for the module in moduleList without first
> seeing another entry into sip_api_export_module.
> 
> I wonder if the following could be happening...
> PyQt5 on my system is precompiled, and then I am building my own code
> that references it. Because siplib.c is generated for each project,
> perhaps the QtCore import is calling a different sip_api_export_module
> and updating a different moduleList than the one implemented in my
> project?
> 
> If this is the explanation, is there a solution short of rebuilding
> PyQt5 as part of my project?
> 
> If it helps, I have attached my pyproject.toml file and the generated
> siblib.c source code.
> 
> I appreciate your help with this.
> 
> -ED

If you are extending PyQt then you need to add PyQt-builder to your 
build system requirements. See something like PyQtChart's 
pyproject.toml.

Phil

> On 14/07/2022 14:04, Edward A. Pier wrote:
>> I have C++ code that depends on Qt5 that I wrap into Python using sip.
>> I am porting code that worked under Ubuntu 20.04 (sip 4.19.21, PyQt5
>> 5.14.1) to run under Ubuntu 22.04 (sip 6.5.1, PyQt5 5.15.6). Now when
>> I import the resulting Python module I get the error in the subject
>> line:
>> 
>> RuntimeError: the PyQt5.QtCore module failed to register with the sip
>> module
>> 
>> I traced this to the generated file siplib.c in the
>> sip_api_export_module function. This function tries to load required
>> modules, of which PyQt5.QtCore is the first. It calls
>> PyImport_ImportModule and then tries to find the module in a linked
>> list kept in the moduleList variable. The problem is that on the first
>> call to sip_api_export_module, moduleList=NULL, i.e. the list is
>> empty, as it only gets updated at the bottom of sip_api_export_module.
>> 
>> So I'm a bit stumped how this could work, unless the first module for
>> which sip_api_export_module is called does not have dependencies, or
>> sip_api_export_module is called for those dependencies first. I've
>> read through the pyproject.toml documentation, but I didn't see any
>> way to make either of these things happen.
> 
> PyImport_ImportModule of QtCore will call QtCore's PyInit_QtCore
> function which itself calls sip_api_export_module and adds QtCore to
> moduleList.
> 
> It sounds like something called QtCore is being successfully imported
> but it's not the QtCore extension module.
> 
>> Let me know what additional information might help get to the bottom 
>> of
>> this.
> 
> The pyproject.toml file might help.
> 
> Phil


More information about the PyQt mailing list