[PyQt] QML plugins - AttributeError: module 'PyQt5' has no attribute 'sip'
Kyle Altendorf
sda at fstab.net
Wed Apr 1 21:10:36 BST 2020
Phil,
Aside from debugging my problem, how do you feel about the second patch?
I don't know my way around the C-API and the docs don't make it clear
to me if the 'pre-import' should be required... but it doesn't seem
like I should be able to do anything outside that would cause the
AttributeError.
Cheers,
-kyle
On 2020-03-07 23:46, Kyle Altendorf wrote:
> I'm working on catching up pyqt5-tools [0] with the new build system
> for PyQt5. I have it building and working in some cases. The present
> issue I am trying to address is the failure of my simple tests of the
> QML plugins when running in GitHub Actions. If I download the wheel
> the build generates and tests against (as far as I know...) it works
> fine locally. On the server I get an error [1].
>
> AttributeError: module 'PyQt5' has no attribute 'sip'
>
> I tried patching qmlscene/pluginloader.cpp [2].
>
> diff --git a/qmlscene/pluginloader.cpp b/qmlscene/pluginloader.cpp
> index 635d31e..5c33b1f 100644
> --- a/qmlscene/pluginloader.cpp
> +++ b/qmlscene/pluginloader.cpp
> @@ -412,9 +412,9 @@ PyObject *PyQt5QmlPlugin::getModuleAttr(const
> char *module, const char *attr)
> void PyQt5QmlPlugin::getSipAPI()
> {
> #if defined(SIP_USE_PYCAPSULE)
> - sip = (const sipAPIDef *)PyCapsule_Import("PyQt5.sip._C_API",
> 0);
> + sip = (const sipAPIDef
> *)PyCapsule_Import("PyQt5.a_sip._C_API", 0);
> #else
> - PyObject *c_api = getModuleAttr("PyQt5.sip", "_C_API");
> + PyObject *c_api = getModuleAttr("PyQt5.b_sip", "_C_API");
>
> if (c_api)
> {
>
> The patched `a_sip` was triggered in CI [3] but not locally. Maybe
> that means that somehow Python is getting initialized previously when
> run locally somehow? (based on the PyQt5QmlPlugin constructor) Or I
> really am not running the same thing locally? I tried a few things
> without any apparent knowledge gain. I'll hope someone here has some
> insight and stop for now with my most recent attempt [4].
>
> diff --git a/qmlscene/pluginloader.cpp b/qmlscene/pluginloader.cpp
> index 635d31e..d6acd6e 100644
> --- a/qmlscene/pluginloader.cpp
> +++ b/qmlscene/pluginloader.cpp
> @@ -412,6 +412,16 @@ PyObject *PyQt5QmlPlugin::getModuleAttr(const
> char *module, const char *attr)
> void PyQt5QmlPlugin::getSipAPI()
> {
> #if defined(SIP_USE_PYCAPSULE)
> + PyObject *mod = PyImport_ImportModule("PyQt5.sip");
> + if (!mod)
> + {
> + PyErr_Print();
> + return;
> + }
> + else
> + {
> + Py_DECREF(mod);
> + }
> sip = (const sipAPIDef *)PyCapsule_Import("PyQt5.sip._C_API",
> 0);
> #else
> PyObject *c_api = getModuleAttr("PyQt5.sip", "_C_API");
>
> This eliminates the error but still fails my tests in CI [5]. The
> tests [6] basically just check for some reference data to be written
> to files by my custom examples when the PyQt5 plugins handle them.
>
> Thanks for any help that you can offer.
>
> Cheers,
> -kyle
>
>
> [0] https://github.com/altendky/pyqt5-tools/pull/41
>
> [1]
> https://gist.githubusercontent.com/altendky/53479b3a57069453f5511b7e02a2e4fd/raw/7bbf58c3d518ea27443eee518e7efa46802d61c4/gistfile1.txt
>
> [2]
> https://github.com/altendky/pyqt5-tools/pull/41/commits/4c72f778afce88c8e68e25fcfad616c2e8b9eec1#diff-44b7c383d27b03d3ef422f5aa45078c5
>
> [3]
> https://gist.githubusercontent.com/altendky/b3d77b52aaa785ed980c7682aaa07f07/raw/b313c3945202cdaae67387cdfd9b5667e1808322/gistfile1.txt
>
> [4]
> https://github.com/altendky/pyqt5-tools/commit/2494b3decf161f49b86174615960610d1078ff03
>
> [5]
> https://gist.githubusercontent.com/altendky/7082b1301aa3c0cf162024d37e52ae72/raw/6e4faa3b484f9d95727b8bbd5399b90d660ab8b9/gistfile1.txt
>
> [6]
> https://github.com/altendky/pyqt5-tools/blob/2494b3decf161f49b86174615960610d1078ff03/src/pyqt5_tools/tests/test_entrypoints.py
More information about the PyQt
mailing list