Error creating a module


I’m following PerkLab’s Slicer bootcamp tutorial on how to create a Module for 3D Slicer. But when I try to run the code to see the changes it returns this error:

ModuleNotFoundError: No module named 'vtkmodules.vtkCommonCore'

I tried to instal this library and vmtk, vtk, itk, but then this error appears:

ImportError: Module use of python39.dll conflicts with this version of Python.

I’m using Windows 10 and python 3.10.6. Does anyone know why this might be happenning, I didn’t found anythin similar

VTK is already installed in 3D Slicer’s Python environment. You must not install VTK using pip, because it may conflict with the version that is bundled already.

Slicer also makes it very convenient to access VTK classes. You don’t need to struggle with finding the right VTK module for a specific class, but instead you can simply use vtk.vtkSomeClassName syntax.

1 Like

@lassoan I’m using VS Code, I don’t know if it’s a problem from the editor with Slicer but it doesn’t seem to be importing none of the packages.

These below are the packages that came when I created the module through Extension Wizard.


VS Code can only load basic Python packages that are available in the standalone Python interpreter that you specify. VS Code does not know about packages that Slicer creates dynamically, so most of the IDE features that depend on static code analysis tools will not work.

To access all packages and classes, documentation, auto-complete, etc., you need to start Slicer and attach VS code to it. See more information starting from this page. Attaching to a running Python interpreter is certainly not as convenient as just running a standalone Python script from the IDE, but once you got used to it, there is not much difference in overall productivity.

1 Like

Sorry to be bothering you again.

But it fails to download the debbuger extension (shown on image below). Do you have any preference or other sugestions on ways to develop scripts to Slicer, I tried to follow some tutorials but wasn’t able to implement my script through none of them.


What Slicer version do you use, on what operating system? Are you behind some kind of firewall or proxy server?

Slicer 5.0.3 on Windows 10.
I am but it usually doesn’t block the download of plugins, packages or even softwares.

The extension manager frontend server downloads packages from the backend server. This operation may be blocked by ghmisconfigured/too aggressive proxy servers.

Please check if you can download if you open the Extensions Manager in your default web browser - see detailed instructions here.

If this does not work then let us know, there are several other ways to do it.

I’m thinking that if the extension manager fails to connect we should put instructions or links to instructions to workarounds directly in the extension manager window. I have another report yesterday about a linux machine behind a hospital firewall that couldn’t access the extension server and the user didn’t know what to do about it (or maybe the info is there and he just missed it - I don’t have the error myself so I’m not sure what is currently displayed).

I also note that our instructions require the user to create the link manually based on the revision numbers and OS. Probably we should provide this link automatically.

1 Like

Hey @lassoan , I tried different methods but the VS Code still doesn’t load slicer.ScriptedLoadableModule and slicer.util. I don’t know what else to try.

import slicer doesn’t work either :frowning:

You can only run the module in Slicer application. Start Slicer, attach the Python debugger, and add a breakpoint where you want to interact with your code.

I attached the python to slicer and still it doesn’t recognize the packages

Attaching the debugger is a good start. Now add a breakpoint and make Slicer reach the breakpoint. You have access to all symbols, packages, etc. in that context.

1 Like

Had some improvements. VS Code still shows warnings about the packages in the file, but Slicer reached the breakpoint. I think that means it worked, might be something in VS Code.

Thank you for all the help!:slight_smile:

VS Code probably uses static code analysis for syntax highlighting, which may prevent it from seeing dynamically loaded packages.

1 Like