I'm currently trying to integrate my C++ Qt5 library in Python using sip based on this tutorial (section "Using a Real Library").
However, I'm having some problems with the Qt5 sip files when I run sip-install
or python -m pip install .
Edit: I found out that i can find the qt bindings in my virtual environment folder: venv/lib/python3.8/site-packages/PyQt5/bindings/ Therefore I tried to set up a fresh virtualenv, install PyQt5 and use this path for sip-include-dirs. But I'm still getting an error:
_in_process.py: /.../venv/lib/python3.8/site-packages/PyQt5/bindings/QtCore/QtCore.toml: 'QtCore' was built against ABI v12.11 but this module is being built against ABI v12.8
Also different versions of PyQt5 and defining sip-abi-version or abi-version in the .toml does not seem to change anything (except that sometimes the /.../bindings folder is empty) What am I doing wrong?
Previous problem description:
Following errors are printed:
/usr/share/sip/PyQt5/QtCore/qglobal.sip: line 114: column 5: 'Qt::KeyboardModifiers::__hash__' must return a Py_hash_t
/usr/share/sip/PyQt5/QtCore/qglobal.sip: line 114: column 5: 'Qt::MouseButtons::__hash__' must return a Py_hash_t
/usr/share/sip/PyQt5/QtCore/qglobal.sip: line 114: column 5: 'Qt::Orientations::__hash__' must return a Py_hash_t
/usr/share/sip/PyQt5/QtCore/qglobal.sip: line 114: column 5: 'Qt::Alignment::__hash__' must return a Py_hash_t
... and about a hundred more of the same kind ...
Probably this is some kind of version incompatibility here. Does anyone know how to fix this?
This is my setup:
$ python
Python 3.8.0 (default, Dec 9 2021, 17:53:27) [GCC 8.4.0] on linux ...
PYQT_VERSION_STR = 5.15.9 ...
QT_VERSION_STR = 5.15.2 ...
Sip version:
$ sip-install --version
6.7.11
$ sip -V
4.19.7 <<<??? This installation appears to be different from the one I did using python -m pip install sip. Is this one active? python -m pip install . works, even if I do python -m pip uninstall sip
Other libs versions:
qtbase5-dev is version (5.9.5+dfsg-0ubuntu2.6).
qtdeclarative5-dev is version (5.9.5-0ubuntu1.1).
Those last two were missing and I had to install them manually
My little test project is very similar to the one in the tutorial, except I include and derive from Qt widgets and include sip-include-dirs to tell sip where to find the Qt sip files:
pyproject.toml:
# Specify sip v6 as the build system for the package.
[build-system]
requires = ["sip >=6, <7"]
build-backend = "sipbuild.api"
# Specify the PEP 566 metadata for the project.
[tool.sip.metadata]
name = "MyProject"
[tool.sip.project]
sip-include-dirs = ["/usr/share/sip/PyQt5/"]
# Configure the building of the fib bindings.
[tool.sip.bindings.MyProject]
headers = ["mywidgets/mywidget.hpp"]
include-dirs = ["/.../my_lib_project/src/"]
libraries = ["mylib"]
library-dirs = ["/.../my_lib_project/build/"]
MyProject.sip:
%Module(name=MyProject, language="C++")
%Import QtCore/QtCoremod.sip
%Import QtWidgets/QtWidgetsmod.sip
class MyWidget : public QWidget
{
%TypeHeaderCode
#include "mywidgets/mywidget.hpp"
%End
public:
MyWidget(QWidget *parent);
};