SystemError when loading custom Python module path

Hi there,

I’m working with Slicer 4.7.0 (see attached screenshot for full details) and I just set a custom Python module path in Edit > Applicaition Settings > Modules. After restarting Slicer I can import my custom module but as soon as the Python console opens I see the following error/warning message:

SystemError: /Users/kitware/Dashboards/Nightly/Slicer-0-build/Python-2.7.13/Objects/classobject.c:521: bad argument to internal function

My custom module script works so I’m not sure whether this is a big problem. Just thought you guys might know what’s going on. Loading a custom Python script seems pretty basic functionality so I was surprised that this error message appears :slight_smile:

Cheers!

Ralph

13

Hi Ralph -

What does your scripted module use? Any binary packages that aren’t built against the Slicer build of python can cause trouble for a binary download of Slicer.

Also a mix of “old style” and “new style” python classes can lead to this message (see the discussions linked below).

If it’s not that can you share the code for an example that leads to the issue? The simplest code that leads to the message would be the most useful.

Best,
Steve

http://massmail.spl.harvard.edu/public-archives/slicer-devel/2014/016962.html

http://slicer-devel-archive.65872.n3.nabble.com/Problems-when-trying-to-build-a-new-extension-td4036566.html

Hi Steve,

My code is no secret. It’s just a file called test_me.py which contains a single method def test_me() that prints “test me”. Can’t get any simpler than that :slight_smile:.

By the way, the function works. It prints out “test me” like it’s supposed to. I was just wondering about the error message.

Cheers,

Ralph

Hi Ralph -

Ah, well, then maybe your code is ‘too simple’ to work that way ; )

We use the term “module” in Slicer to refer to something pretty specific that implements GUI and Logic classes. That’s what the Module Paths in the settings refers to.

https://www.slicer.org/wiki/Documentation/Nightly/Developers/Modules#Scripted_Modules

If what you want to do is set up the code like a test_me function to run every time Slicer starts, you can set up a .slicerrc.py file in your home directory as described here:

https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_systematically_execute_custom_python_code_at_startup_.3F

Hope that helps!
-Steve

Ralph, you can put your custom (non-Slicer) Python packages in subdirectories within the folder that you specify in “Additional module paths”.

1 Like

Hi Steve,

Ok, that was not clear from the what was written at the beginning of the documentation at Documentation/Nightly/ScriptRepository - Slicer Wiki. It mentioned "save the .py file to a directory and add the directory to the additional module paths in the Slicer application settings. No mention of a module being anymore than a regular Python module.

Anyway, thanks for looking into this!

Ralph

Aha, I see - okay, I updated the wiki page to clarify:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Community-contributed_modules

Let us know if other things aren’t clear.

Best,
Steve