Orthanc on Ubuntu, Can't run Python Scripts

Good day everyone, hope you are doing very well.

I have installed Orthanc on Ubuntu by following the documentation here:

https://orthanc.uclouvain.be/book/users/debian-packages.html

And it starts beautifully.

However, I do want to write python scripts to interact with the restapi but it keeps saying “module orthanc not found”.

In my /etc/orthanc/orthanc.json file this the contents:

{
“Plugins” : [
“/usr/share/orthanc/plugins”
],
“PythonScript” : “/tmp/hello.py”,
.
.
.
}

I am trying to run python3 /tmp/hello.py but not luck at all.

Even the sample.py that resides in /etc/orthanc still doesn’t work

Hi,

I have just updated the python documentation with this section:


The Orthanc plugins interfaces are exposed in an orthanc module that you should include in your script through import orthanc. This module is only available when the script is running inside Orthanc. It is therefore not possible to execute your script outside of Orthanc. If you need to develop a complex plugin, it is advised to split it in 2

  • One part that is independent from the orthanc module that you can develop and test locally.
  • One small part that is using the orthanc module and that acts as glue-code between Orthanc and your business logic.

Hope this helps,

Alain

Thanks Alain.

I guess my follow up question will be, how would I run a python script inside Orthanc then.

This seems correct. Check your logs to validate that the python plugin is loaded and add print statements in the python file to make sure it is being executed.

I guess my follow up question will be, how would I run a python script inside Orthanc then.

kabary : the script is automatically executed when Orthanc starts. The usual way of working with Python and Orthanc is, in the script itself, to register callbacks that will be called later on on some events.

Check out the examples on this page , for instance this one