# SystemError when loading custom Python module path

**URL:** <https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207>\
**Category:** Support\
**Tags:** extensions-manager\
**Created:** [October 11, 2017, 11:07am UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207 "2017-10-11T11:07:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbrecheisen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbrecheisen/32/726_2.png) [@rbrecheisen](https://discourse.slicer.org/u/rbrecheisen)\
**Post date:** [October 11, 2017, 11:07am UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/1 "2017-10-11T11:07:03Z")

</div>

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 🙂

Cheers!

Ralph

![13](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/d/6dd83fd761e5972c3cb0b968108be3f9cb4327be.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:** [October 11, 2017, 12:47pm UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/2 "2017-10-11T12:47:49Z")

</div>

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://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](http://slicer-devel-archive.65872.n3.nabble.com/Problems-when-trying-to-build-a-new-extension-td4036566.html)

---

<div class="post-metadata">

**Author:** ![rbrecheisen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbrecheisen/32/726_2.png) [@rbrecheisen](https://discourse.slicer.org/u/rbrecheisen)\
**Post date:** [October 11, 2017, 9:39pm UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/3 "2017-10-11T21:39:18Z")

</div>

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 🙂.

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

---

<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:** [October 11, 2017, 10:55pm UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/4 "2017-10-11T22:55:59Z")

</div>

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](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](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_systematically_execute_custom_python_code_at_startup_.3F)

Hope that helps!  
-Steve

---

<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:** [October 12, 2017, 4:34am UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/5 "2017-10-12T04:34:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rbrecheisen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbrecheisen/32/726_2.png) [@rbrecheisen](https://discourse.slicer.org/u/rbrecheisen)\
**Post date:** [October 12, 2017, 4:50am UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/6 "2017-10-12T04:50:49Z")

</div>

Hi Steve,

Ok, that was not clear from the what was written at the beginning of the documentation at [Documentation/Nightly/ScriptRepository - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository). 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.

 ![41](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/e/2ef261eaef4f12f5b3f46066411f309d4f002eac.png)

Anyway, thanks for looking into this!

Ralph

---

<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:** [October 12, 2017, 11:45am UTC](https://discourse.slicer.org/t/systemerror-when-loading-custom-python-module-path/1207/7 "2017-10-12T11:45:40Z")

</div>

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

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Community-contributed\_modules](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Community-contributed_modules)

Let us know if other things aren’t clear.

Best,  
Steve
