1

Python version: 3.8.1 Spyder version: 3.3.6 Qt version: 5.12.9 Wrapper: develop using PyBind11

I am wrapping a dll develop in C++ which use Qt dlls to be used with Python. I wrote the wrapper with Visual Studio 2019 using the compiler MSVC (as my dll is compiled with MSVC). After generating the solution in VS2019 I obtain a .pyd file which can be import with python.

It works good when I use python on line command:

  1. Start cmd.exe
  2. $python
  3. import MyLibName I can use the functions/classes ...

But if I try with Spyder, I get the following error:

ImportError: DLL load failed while importing PyStack: The specified module could not be found..

So here are my questions :

Is there a way to get more information about ImportError like the name of the missing dll or something?

I don't understand why the issue only happen with spyder. I tried with IPython Qt Console and it work. Does spyder use a embeded python version or something ?

I don't fully understand how dll shall be managed, I mean shall I provide dll like libGLESV2.dll with the .pyd or just give a path where to find it ?

Thank you in advance.

Teddy
  • 57
  • 1
  • 7
  • How did you install `Qt` and `pybind` ? Spyder uses `conda` installed python. I guess you installed your libraries on the system's python, while spyder uses another version – Christian Jan 31 '21 at 20:34
  • Hello Christian, – Teddy Feb 01 '21 at 06:45
  • Hello Christian. I used Qt installer provided in qt.io, I selected some versions that I needed (5.12.9, 5.15.1 etc.). I installed 2 version of python (32bits : 3860 and 64bits:3810) using WinPython. I installed pybind 2 times using pip (I used 2 different path to install it both python versions). My library isn't install I just compile my VS project which give me an .pyd that I import in script. I also tried to import my library on other computer, it works without installing pybind. May be spyder use different python install can I get the path used using python command ? – Teddy Feb 01 '21 at 07:01
  • Yes you can try the answer [here](https://stackoverflow.com/a/2589722/3283333) – Christian Feb 01 '21 at 07:17
  • I tried this before and I get the same result : C:\WPy64-3810\python-3.8.1.amd64\python.exe Some python.exe are the same. May be they have a different configuration ? – Teddy Feb 01 '21 at 07:26
  • Okay, could you provide the whole error message maybe? – Christian Feb 01 '21 at 12:26
  • I do some test to see if I can reproduce the error on other console. I was able to reproduce it on VS Code and Pyzo. I check the module list in sys.modules (in spyder console) and import them in windows shell. Here is the error message (PyStack is the name of my lib) ``` Traceback (most recent call last): File "", line 1, in ImportError: dynamic module does not define module export function (PyInit_PyStack) ``` – Teddy Feb 02 '21 at 07:00
  • Sorry I mistaken, importing all modules from sys.modules doesn't reproduce the error... The import error is : Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed while importing PyStack: La procédure spécifiée est introuvable La procédure spécifiée est introuvable = is equivalent to The specified procedure cannot be found – Teddy Feb 02 '21 at 07:14
  • Good if you solved your issue (pas de soucis je parle aussi français). – Christian Feb 02 '21 at 15:50
  • In fact I didn't solved but I progress, the issue is link to the pyQt5 version used. I make it work (without trick like not using qt gui), but the user shall install pyqt with the same version as mine (used to compile the dll). Cool ^^ je continue en anglais si par hasard des anglophones ont le même problème – Teddy Feb 02 '21 at 15:56
  • Eheh oui, en anglais, sinon la question va être fermée ;-) – Christian Feb 03 '21 at 06:51

1 Answers1

1

My guess

I think I find out which part of Qt/python is producing this issue, but I still don't know how to solve it.

My dll use signals/slots which need an event loop to be performed. If an event loop is already running the dll will try to use it, if the loop version (ex : PyQt5==5.14.1) isn’t the same as mine (ex Qt==5.15.1) import will be impossible.

Note that the reverse is true, if I run my dll an then try to start a loop with %gui qt the command will throw an error.

How to reproduce the issue :

  1. Compile a Qt project available here.
  2. Copy the output dll in the folder PyMyStack/dependencies of the VS Project (available here)
  3. Compile the VS project.
  4. Open an IPython console (without using qt has event loop)
  5. Import the module created with VS (Import PyMyStack)
  6. Run the magic command %gui qt

Last command shall print : ERROR:root:DLL load failed while importing QtSvg: The specified procedure could not be found.

How to hide/solve the problem:

Disclaimer : The solutions presented here are surely not the best, if you know a better one please share it ☺

If you just want to import your lib in Spyder, you can use another event loop. Here are the steps to change this:

  1. In Spyder menus go to Tools→Preferences
  2. Select “IPython console”
  3. Go to “Graphics” tab and change the backend combo box to any other values than Qt or Automatic

If you want to use Qt event loop you will have to update it. You can do this with pip command, but remember than Spyder is not compatible with some version. Here is the pip command:

Pip install PyQt5==X.Y.Z

Where X and Y are the same version use to compile your Qt project. The last digit version seems to not be important.

Teddy
  • 57
  • 1
  • 7
  • I am not too sure I understand exactly your problem, is there a way you can provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) ? – Christian Feb 03 '21 at 06:53
  • I am working on it. I will post it as soon as possible – Teddy Feb 03 '21 at 16:28