Python message: "Failed to import PythonQt.qSlicerxxxxModuleWidgets"

Dear All,

I’m Andrea Vitali from University of Bergamo (Italy) and our students faced a specific problem during the development of a C++ module based on the template “loadablecustommarkups”.

In particular, we have problems with creating the loadable-custom-markups module in 3Dslicer version 4.13.0 for Windows 10 with Visual Studio 2019, Qt5 version 5.0.2 and Cmake version 3.15.4. We followed the instructions in the 3D-slicer documentation:

  • Setting up the source and debug-mode build folder respectively named "S4_13" and "S4_13D",
  • Creating an extension and adding a "custom loadable markup" module from “Extension Wizard”,
  • Compiling files using c-make by entering the path to source and debug-mode build folder, where it’s necessary the .git file in our module,
  • Opening the project in Visual Studio and compiling "All-build" project,

Despite this, when we try to open the Slicer.exe file, we get errors with the message “Failed to import PythonQt.qSlicercustomMarkupModuleWidgets”.
While if we create a standard loadable module with the same procedure, no error appears.

I also found this post “Build error caused by qSlicerSubjectHierarchyPlotsPlugin” in which the same error was relative to the maximum lenght of the file name. Coudl it be the same issue?

Thanks in advance,

Regards,
Andrea Vitali


Yes, it could be the path. Be sure to use something very short. I use c:/s for debug and c:/sr for release builds in windows.

Hi Steve,

thank you for your replay. However, the error still remain. We have tried with the generation of a standard loadable module and everything works fine.

I think that it should be better to move the discussion in the section “Development”.

Regards,

Hi,

We are experiencing the same situation on Windows 10, with a library compiled with our extension. The compiled .lib lives in the solution directory, close to C:\ to avoid any path-length related issues. Yet, the python script to build the UI fails to find the library and halts the execution, leaving the UI partly built. 3DSlicer v4.13.0, VS 2019 v16, Qt 5.15.02 and CMake 3.22.1.

The library is exported using the directive Q_SLICER_MODULE_${MODULE_NAME_UPPER}_WIDGETS_EXPORT and built using the flag WRAP_PYTHONQT (SlicerMacroBuildModuleWidget)

@RafaelPalomar

Hi Javier,

I have also tried:

  1. Generate the markups module library directly inside C:
  2. Name the module with a single letter (“m”)

The error still occur. I hope in the developers’ help.

@AndreaVitali86, @jpdefrutos, the problem looks similar, but we cannot conclude it is the same problem yet.

What we have seen with @jpdefrutos is that PythonD libraries generated are .lib files (I’m not a Windows user of Slicer, but I would expect a .dll to be generated in order to be loaded in run-time).

@pieper, @lassoan, @jcfr does this make sense?

This is sounding like a cmake library issue either not generating, building, or copying the python wrapper files correctly. It might also be that they aren’t being put in the path correctly for the launcher. Maybe a good debug strategy would be to look at the files generated for loadable module code that works as expected in python and then see the corresponding pattern of wrapped code and libraries for any differences with the custom markup code.

Can you post a link to your source code? Do you only see the errors if you try to use the qSlicerexePModuleWidgets from a Python scripted module?

Hi all,

I conferm the same issue mentioned by @RafaelPalomar: we have a
qSlicerCustomModuleWidgetsPythonQt.lib instead of the .dll file

We have to check how the files are generated in Visual Studio as suggested by @pieper. I will do it the next week.

About the questions of @lassoan:

  • Can you post a link to your source code?
    I can post the code but we did not develop custom code inside the software modules automatically generated by the custom markups widget template.
    Anyway, this is the github repo: https://github.com/AndreaVitali86/SlicerCustomMarkups

  • Do you only see the errors if you try to use the qSlicerexePModuleWidgets from a Python scripted module?
    The code is relative to a loadable module (C++) so, the builded files are imported during the initiliazation of 3D slicer: when the initialization phase of all the modules finishes the python console give us the reported error. In other words, we are not using a Python scripted module.

Thank you very much for your efforts.

I’ve submitted a pull request that fixes the module:

The problem was that the code pieces that allow the template to be used as a test need to be removed.

I could not find the root cause of why Python-wrapping of the widgets does not work correctly (and thus the Python module cannot be imported and the Failed to import PythonQt.qSlicerCustomMarkupsModuleWidgets error is logged). But this extension does not seem to have this issue, so by making this extension more similar to it should fix the issue:

1 Like