[PySide] My first Shiboken6-based bindings: module import error

Filippo Rusconi listes.rusconi at laposte.net
Wed Nov 23 17:37:16 CET 2022


Greetings,

I am starting the Python/PySide6/Shiboken6 journey. I built Pyside6 from source
fine (git branch 6.3; SetupTools workflow) as per the instructions.  I could
configure a simple bindings setup where I generate bindings for one struct (my
project is a library in C++/Qt6).  The struct is very simple:

struct PMSPP_LIB_DECL DataPoint
{
   pappso_double x = -1;
   pappso_double y = 0;

   DataPoint();
   DataPoint(const DataPoint &other);
   DataPoint(pappso_double x, pappso_double y);
   DataPoint(std::pair<pappso_double, pappso_double> pair);
   DataPoint(const QString &text);

   // For debugging purposes.
   //~DataPoint();

   DataPointCstSPtr makeDataPointCstSPtr() const;

   void initialize(pappso_double x, pappso_double y);
   void initialize(const DataPoint &other);
   bool initialize(const QString &text);

   void reset();

   void incrementX(pappso_double value);
   void incrementY(pappso_double value);

   bool operator==(const DataPoint &other) const;

   DataPoint &operator=(const DataPoint &other);

   bool isValid() const;

   QString toString() const;
   QString toString(int decimals) const;
};

I can build the bindings shared library fine.

Then I start the Python interpreter and 'import <module name>' but I get this
error message:

ImportError: could not import module 'PySide6.QtCore'

That is odd, because I have set PYTHONPATH to the directory were all the shared
libs are located. If I 'import PySide6', the module is loaded fine.

I thus tried to dig a bit:

>>> dir(PySide6)

['Path', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '__version_info__', '_additional_dll_directories', '_find_all_qt_modules', '_setupQtDirectories', 'dedent', 'os', 'support', 'sys']

>>> PySide6._find_all_qt_modules()
['QtCore', 'QtGui', 'QtWidgets', 'QtPrintSupport', 'QtSql', 'QtNetwork', 'QtTest', 'QtConcurrent', 'QtDesigner', 'QtXml', 'QtHelp', 'QtMultimedia', 'QtMultimediaWidgets', 'QtOpenGL', 'QtOpenGLWidgets', 'QtQml', 'QtQuick', 'QtQuickControls2', 'QtQuickWidgets', 'QtSvg', 'QtSvgWidgets', 'QtUiTools', 'QtDBus']

So I tried this:

>>> from PySide6 import QtCore

ImportError: libpyside6.cpython-310-x86_64-linux-gnu.so.6.3: cannot open shared object file: No such file or directory

But that library happens to be in the PYTHONPATH:

>>> print(sys.path)
['/home/rusconi/devel/small-pyside6/lib/python3.10/site-packages', ...snip...]

 From the shell:

% ls /home/rusconi/devel/small-pyside6/lib/python3.10/site-packages/PySide6
assistant                                          Qt                                                   QtNetwork.cpython-310-x86_64-linux-gnu.so         QtSql.pyi
_config.py                                         QtConcurrent.cpython-310-x86_64-linux-gnu.so         QtNetwork.pyi                                     QtSvg.cpython-310-x86_64-linux-gnu.so
designer                                           QtConcurrent.pyi                                     QtOpenGL.cpython-310-x86_64-linux-gnu.so          QtSvg.pyi
examples                                           QtCore.cpython-310-x86_64-linux-gnu.so               QtOpenGL.pyi                                      QtSvgWidgets.cpython-310-x86_64-linux-gnu.so
__feature__.pyi                                    QtCore.pyi                                           QtOpenGLWidgets.cpython-310-x86_64-linux-gnu.so   QtSvgWidgets.pyi
_git_pyside_version.py                             QtDBus.cpython-310-x86_64-linux-gnu.so               QtOpenGLWidgets.pyi                               QtTest.cpython-310-x86_64-linux-gnu.so
glue                                               QtDBus.pyi                                           QtPrintSupport.cpython-310-x86_64-linux-gnu.so    QtTest.pyi
include                                            QtDesigner.cpython-310-x86_64-linux-gnu.so           QtPrintSupport.pyi                                QtUiTools.cpython-310-x86_64-linux-gnu.so
__init__.py                                        QtDesigner.pyi                                       QtQml.cpython-310-x86_64-linux-gnu.so             QtUiTools.pyi
libpyside6.cpython-310-x86_64-linux-gnu.so.6.3     QtGui.cpython-310-x86_64-linux-gnu.so                QtQml.pyi                                         QtWidgets.cpython-310-x86_64-linux-gnu.so
libpyside6qml.cpython-310-x86_64-linux-gnu.so.6.3  QtGui.pyi                                            QtQuickControls2.cpython-310-x86_64-linux-gnu.so  QtWidgets.pyi
linguist                                           QtHelp.cpython-310-x86_64-linux-gnu.so               QtQuickControls2.pyi                              QtXml.cpython-310-x86_64-linux-gnu.so
lrelease                                           QtHelp.pyi                                           QtQuick.cpython-310-x86_64-linux-gnu.so           QtXml.pyi
lupdate                                            QtMultimedia.cpython-310-x86_64-linux-gnu.so         QtQuick.pyi                                       scripts
__pycache__                                        QtMultimedia.pyi                                     QtQuickWidgets.cpython-310-x86_64-linux-gnu.so    support
py.typed                                           QtMultimediaWidgets.cpython-310-x86_64-linux-gnu.so  QtQuickWidgets.pyi                                typesystems
qmllint                                            QtMultimediaWidgets.pyi                              QtSql.cpython-310-x86_64-linux-gnu.so

We can see that libpyside6.cpython-310-x86_64-linux-gnu.so.6.3 is actually there
and also all the other modules, in particular
QtCore.cpython-310-x86_64-linux-gnu.so.

What am I doing wrong here ?

Thank you for your patience

Sincerely,
newbie Filippo

-- 
⢀⣴⠾⠻⢶⣦⠀  Filippo Rusconi, PhD
⣾⠁⢠⠒⠀⣿⡁   Research scientist at CNRS
⢿⡄⠘⠷⠚⠋⠀   Debian Developer
⠈⠳⣄⠀⠀⠀⠀  http://msxpertsuite.org
           http://www.debian.org




More information about the PySide mailing list