Module not found error

while writing python plugins I get the following error log:

“module named orthanc not found”

when i use the line “import orthanc” in the plugin code.

May I please know how to overcome this ?

Full code may be found below :slight_smile:

import json
import inspect
import orthanc
import pynetdicom

def HandleStore(event):
orthanc.LogWarning(‘Handling C-STORE using pynetdicom’)
orthanc.RestApiPost(‘/instances’, event.request.DataSet.getvalue())
return 0x0000

ae = pynetdicom.AE()
ae.supported_contexts = pynetdicom.AllStoragePresentationContexts

SCP = None

def OnChange(changeType, level, resource):
global SCP

if changeType == orthanc.ChangeType.ORTHANC_STARTED:
    port = json.loads(orthanc.GetConfiguration()).get('DicomPort', 4243)
    
    SCP = ae.start_server(('', port), block = False, evt_handlers = [
        (pynetdicom.evt.EVT_C_STORE, HandleStore),
    ])
    
    orthanc.LogWarning('DICOM server using pynetdicom has started')

elif changeType == orthanc.ChangeType.ORTHANC_STOPPED:
    orthanc.LogWarning('Stopping pynetdicom')
    SCP.shutdown()

orthanc.RegisterOnChangeCallback(OnChange)

Hello,

Do not hesitate to greet the community, if not out of proper education, at least so that people are more likely to help you. We wish for this forum to be a friendly and welcoming place. Thank you.

Could you please share your .json configuration file and the path where your .py script is saved?

Also, please give details about your OS, environment, Python versions…

Your complete log file up to the error message could also be useful!

Thanks in advance

Hello,

You are most likely trying to execute a sample Python plugin outside of Orthanc. Python plugins cannot be executed as standalone Python scripts, because the orthanc module is installed by the Orthanc core.

Check out the Orthanc Book for instructions.

Best Regards,
Sébastien-