# Python message: "Failed to import PythonQt.qSlicerxxxxModuleWidgets"

**URL:** <https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575>\
**Category:** Development\
**Tags:** extensions-manager, python, markups-fiducials\
**Created:** [January 22, 2022, 3:54pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575 "2022-01-22T15:54:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreaVitali86](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andreavitali86/32/13888_2.png) [@AndreaVitali86](https://discourse.slicer.org/u/AndreaVitali86)\
**Post date:** [January 22, 2022, 3:54pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/1 "2022-01-22T15:54:55Z")

</div>

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](https://discourse.slicer.org/t/build-error-caused-by-qslicersubjecthierarchyplotsplugin/2060)” 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

 ![Error3Dslicer](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/4/0429be2e38678ca539510218141b4b8de7e24af8.png)  
 ![ErrorInEXE](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/5/559a3b1815464f9e924b3c732de05023c59830be.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 22, 2022, 4:30pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/2 "2022-01-22T16:30:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AndreaVitali86](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andreavitali86/32/13888_2.png) [@AndreaVitali86](https://discourse.slicer.org/u/AndreaVitali86)\
**Post date:** [January 24, 2022, 10:24am UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/3 "2022-01-24T10:24:22Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![jpdefrutos](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jpdefrutos/32/13935_2.png) [@jpdefrutos](https://discourse.slicer.org/u/jpdefrutos)\
**Post date:** [January 25, 2022, 1:10pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/4 "2022-01-25T13:10:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![AndreaVitali86](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andreavitali86/32/13888_2.png) [@AndreaVitali86](https://discourse.slicer.org/u/AndreaVitali86)\
**Post date:** [January 25, 2022, 4:45pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/5 "2022-01-25T16:45:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [January 26, 2022, 10:12am UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/6 "2022-01-26T10:12:23Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 26, 2022, 12:49pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/7 "2022-01-26T12:49:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 27, 2022, 2:23pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/8 "2022-01-27T14:23:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![AndreaVitali86](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/andreavitali86/32/13888_2.png) [@AndreaVitali86](https://discourse.slicer.org/u/AndreaVitali86)\
**Post date:** [January 28, 2022, 7:27pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/9 "2022-01-28T19:27:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 28, 2022, 9:28pm UTC](https://discourse.slicer.org/t/python-message-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/10 "2022-01-28T21:28:05Z")

</div>

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

> <https://github.com/AndreaVitali86/SlicerCustomMarkups/pull/1>
>
> Fixes the module that is discussed at
> https://discourse.slicer.org/t/python-mes…sage-failed-to-import-pythonqt-qslicerxxxxmodulewidgets/21575/9
> 
> The error message still persists and the markup option widget is not available in Python, but everything else works.
> The https://github.com/SlicerHeart/SlicerSurfaceMarkup extension does not seem to have this issue, so it could be fixed by careful comparison.

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:

> **[GitHub - SlicerHeart/SlicerSurfaceMarkup: Extension to test the new grid...](https://github.com/SlicerHeart/SlicerSurfaceMarkup)**
>
> Extension to test the new grid surface markup with - GitHub - SlicerHeart/SlicerSurfaceMarkup: Extension to test the new grid surface markup with
