# Importing custom python module into scripted extension

**URL:** https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673
**Category:** Development
**Tags:** extensions-manager, python, module
**Created:** [May 23, 2020, 3:27am UTC](https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673 "2020-05-23T03:27:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![talmazov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/talmazov/32/3966_2.png) [@talmazov](https://discourse.slicer.org/u/talmazov)
#### Post date: [May 23, 2020, 3:27am UTC](https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673/1 "2020-05-23T03:27:56Z")

</div>

Hey all,  
I have a custom python file asyncsocket.py that contains some code independent of 3d slicer. I am trying to import that module to use in a scripted widged by doing  
import asyncsocket  
howeveri get this  
RuntimeError: qSlicerScriptedLoadableModule::setPythonSourc  
apperently it is not a scripted loadable module. this is a generic python code that utilizes only core python function  
asyncsocket.py is in the same directory as the slicer scripted widget

Thanks!

---

<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: [May 23, 2020, 4:18am UTC](https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673/2 "2020-05-23T04:18:32Z")

</div>

This topic should help:

> [@Python scripted module code organization](https://discourse.slicer.org/t/python-scripted-module-code-organization/6339/2):
>
> Python modules must be in subfolder(s). See for example how it is done in [DataProbe module](https://github.com/Slicer/Slicer/tree/master/Modules/Scripted/DataProbe).

---

<div class="post-metadata">

### Author: ![adamrankin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/adamrankin/32/155_2.png) [@adamrankin](https://discourse.slicer.org/u/adamrankin)
#### Post date: [May 17, 2023, 1:40pm UTC](https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673/3 "2023-05-17T13:40:52Z")

</div>

FYI this is the first google hit on the subject

---

<div class="post-metadata">

### Author: ![talmazov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/talmazov/32/3966_2.png) [@talmazov](https://discourse.slicer.org/u/talmazov)
#### Post date: [July 10, 2023, 1:37am UTC](https://discourse.slicer.org/t/importing-custom-python-module-into-scripted-extension/11673/4 "2023-07-10T01:37:56Z")

</div>

this was fixed by placing the custom python file in a subdirectory (eg. comm) of the scriptable module and using

example: from comm import asyncsock

in comm folder there is

` __init__.py`

which contains

from .asyncsock import \*
