Python causing Orthanc to Stop

  1. Installed Python311 to all Users

  2. Add to both variables enviroment the Path C:\Program Files\Python311; (also tried without “;”)

  3. Tried to add Both .dll availiable for x64 and 32x on Repository, but I think mainline is the correct (One file per test, obviously)

  4. Added to orthan.json
    “Plugins” : [ “C:\Program Files\Orthanc Server\Plugins” ],
    “PythonScript” : “C:\Program Files\Orthanc Server\Python Scripts\rest.py”,
    “PythonVerbose” : false,

  5. Log says
    MAIN PluginsManager.cpp:157] Sample worklist plugin is finalizing
    E0307 15:44:13.817279 MAIN main.cpp:2106] Uncaught exception, stopping now: [Error while using a shared library (plugin)] (code 25)
    W0307 15:44:13.817279 MAIN main.cpp:2137] Orthanc has stopped

Rest.py contains:
import orthanc
import pprint

def OnRest(output, uri, **request):
pprint.pprint(request)
print(‘Accessing uri: %s’ % uri)
output.AnswerBuffer(‘ok\n’, ‘text/plain’)

orthanc.RegisterRestCallback(‘/(to)(t)o’, OnRest)
orthanc.RegisterRestCallback(‘/tata’, OnRest)

Im not giving a single step forward once again, the whole morning trying to figure out whats wrong. Im new at this stuff, but I don’t seem to be forgetting anything.

If you are using Orthanc for Windows, try using \\ instead of \ in your path like this

“PythonScript” : “C:\\Program Files\\Orthanc Server\\Python Scripts\\rest.py”

What version of python did you install?
Python seems to be added to path.
Did you install python as administrator or user?

When Orthanc crashes while loading a script, two logs are generated; examine the Python error logs for insights. The problem may arise from Orthanc’s search for packages in the system site-packages folder. One resolution is to run Orthanc at the user level, though challenges may be encountered. To address the issue, a workaround involves importing global packages first, then specifying the user-level site-packages folder location and importing the remaining packages. The provided code snippet demonstrates this approach:

import sys
import orthanc
sys.path.append(r’C:\Users\user\AppData\Roaming\Python\Python311\site-packages’)
from PIL import Image
import imagehash
import numpy as np

I think it’s a behaviour of Ctrl+C/V here in the Community, my code is currently with \, but it’s the second time I’ve pasted her and it turned into one!

This part is fine

Edit: OK, doc leads us to a 32-bit link

changed it to

Now it’s working!

Ok, got a new clue, it’s the DLL that’s actually crashing.

0308 14:19:41.257927 MAIN PluginsManager.cpp:303] (plugins) Found a shared library: “C:\Program Files\Orthanc Server\Plugins\OrthancPython-Python3.11-mainline.dll”
E0308 14:19:41.289731 MAIN SharedLibrary.cpp:50] LoadLibrary(C:\Program Files\Orthanc Server\Plugins\OrthancPython-Python3.11-mainline.dll) failed: Error 193
E0308 14:19:41.289731 MAIN OrthancException.cpp:61] Error while using a shared library (plugin): You are most probably trying to load a 32bit plugin into a 64bit version of Orthanc

Python 3.11.0
Plugin OrthancPython-Python3.11-mainline

Everythings is x64

Edit: OK, Orthanc leads us to a 32-bit link

changed it to

Now it’s working!

Ok, got a new clue, it’s the DLL that’s actually crashing.

0308 14:19:41.257927 MAIN PluginsManager.cpp:303] (plugins) Found a shared library: “C:\Program Files\Orthanc Server\Plugins\OrthancPython-Python3.11-mainline.dll”
E0308 14:19:41.289731 MAIN SharedLibrary.cpp:50] LoadLibrary(C:\Program Files\Orthanc Server\Plugins\OrthancPython-Python3.11-mainline.dll) failed: Error 193
E0308 14:19:41.289731 MAIN OrthancException.cpp:61] Error while using a shared library (plugin): You are most probably trying to load a 32bit plugin into a 64bit version of Orthanc

Python 3.11.0
Plugin OrthancPython-Python3.11-mainline

Everythings is x64.

How is it probably 32? haha

Maybe your Python install is 32 bits ?

Try running it with Process Monitor as explained here to find the root cause of the problem.