# Python causing Orthanc to Stop

**URL:** https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420
**Category:** General
**Created:** [March 7, 2024, 4:13pm UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420 "2024-03-07T16:13:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gutocastiglioni](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gutocastiglioni](https://discourse.orthanc-server.org/u/gutocastiglioni)
#### Post date: [March 7, 2024, 4:13pm UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/1 "2024-03-07T16:13:55Z")

</div>

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)

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

---

<div class="post-metadata">

### Author: ![sonaliayash](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/sonaliayash/32/1930_2.png) [@sonaliayash](https://discourse.orthanc-server.org/u/sonaliayash)
#### Post date: [March 8, 2024, 6:11am UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/2 "2024-03-08T06:11:02Z")

</div>

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”`

---

<div class="post-metadata">

### Author: ![T61](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@T61](https://discourse.orthanc-server.org/u/T61)
#### Post date: [March 8, 2024, 11:31am UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/3 "2024-03-08T11:31:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gutocastiglioni](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gutocastiglioni](https://discourse.orthanc-server.org/u/gutocastiglioni)
#### Post date: [March 8, 2024, 12:23pm UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/4 "2024-03-08T12:23:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![gutocastiglioni](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gutocastiglioni](https://discourse.orthanc-server.org/u/gutocastiglioni)
#### Post date: [March 8, 2024, 2:22pm UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/5 "2024-03-08T14:22:04Z")

</div>

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

> **[Orthanc downloads](https://orthanc.uclouvain.be/downloads/windows-32/orthanc-python/index.html)**
>
> Downloads that are available from the Orthanc project.

changed it to

> **[Orthanc downloads](https://orthanc.uclouvain.be/downloads/windows-64/orthanc-python/index.html)**
>
> Downloads that are available from the Orthanc project.

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

---

<div class="post-metadata">

### Author: ![gutocastiglioni](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gutocastiglioni](https://discourse.orthanc-server.org/u/gutocastiglioni)
#### Post date: [March 8, 2024, 2:22pm UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/6 "2024-03-08T14:22:24Z")

</div>

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

> **[Orthanc downloads](https://orthanc.uclouvain.be/downloads/windows-32/orthanc-python/index.html)**
>
> Downloads that are available from the Orthanc project.

changed it to

> **[Orthanc downloads](https://orthanc.uclouvain.be/downloads/windows-64/orthanc-python/index.html)**
>
> Downloads that are available from the Orthanc project.

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

---

<div class="post-metadata">

### Author: ![alainmazy](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/alainmazy/32/1576_2.png) [@alainmazy](https://discourse.orthanc-server.org/u/alainmazy)
#### Post date: [March 11, 2024, 11:02am UTC](https://discourse.orthanc-server.org/t/python-causing-orthanc-to-stop/4420/7 "2024-03-11T11:02:13Z")

</div>

> [@gutocastiglioni](#):
>
> How is it probably 32? haha

Maybe your Python install is 32 bits ?

Try running it with Process Monitor as [explained here](https://discourse.orthanc-server.org/t/orthanc-as-a-service-stops-when-a-python-script-is-provided/2748/4) to find the root cause of the problem.
