Python Plugin: PyDicom import fail

Similar to: Orthanc python plugin : Python script cant read all needed packages ,

I get an error when importing the pydicom python package from a Orthanc Python Plugin:

orthanc-1  | W0924 13:38:56.896859             MAIN PluginsManager.cpp:158] Python plugin is initializing
orthanc-1  | W0924 13:38:56.897102             MAIN PluginsManager.cpp:158] Using Python script "assign_location_plugin.py" from directory: /etc/orthanc
orthanc-1  | W0924 13:38:56.897110             MAIN PluginsManager.cpp:158] Force global loading of Python shared library: /lib/x86_64-linux-gnu/libpython3.11.so.1.0
orthanc-1  | W0924 13:38:56.897136             MAIN PluginsManager.cpp:158] Program name: /usr/local/sbin/Orthanc
orthanc-1  | sys.path before modification: /etc/orthanc, /usr/lib/python311.zip, /usr/lib/python3.11, /usr/lib/python3.11/lib-dynload, /usr/local/lib/python3.11/dist-packages, /usr/lib/python3/dist-packages
orthanc-1  | E0924 13:38:56.912457             MAIN PluginsManager.cpp:154] Error during the installation of the Python script, traceback:
orthanc-1  | <class 'ModuleNotFoundError'>
orthanc-1  | No module named 'pydicom'
orthanc-1  | 
orthanc-1  |   File "/etc/orthanc/assign_location_plugin.py", line 5, in <module>
orthanc-1  |     from pydicom import dcmread, dcmwrite
orthanc-1  | 
orthanc-1  | E0924 13:38:56.912483             MAIN PluginsManager.cpp:92] Error while initializing plugin /usr/local/share/orthanc/plugins/libOrthancPython.so (code -1)

From the latest documentation it seems that pydicom is already installed (Python plugin for Orthanc — Orthanc Book documentation).

At the top of my python plugin I have:

import sys
print("sys.path before modification: " + ", ".join(sys.path))
from io import BytesIO

from pydicom import dcmread, dcmwrite
from pydicom.filebase import DicomFileLike
from pydicom.sequence import Sequence
from pydicom.dataset import Dataset

import orthanc

This is my docker-compose.yml:

services:
  orthanc:
    restart: always
    image: jodogne/orthanc-python:latest
    command: /run/secrets/  # Path to the configuration files (stored as secrets)
    ports:
      - 4242:4242
      - 8042:8042
    volumes:
      - ../orthanc_plugins/assign_location_plugin.py:/etc/orthanc/assign_location_plugin.py
    secrets:
      - orthanc.json
    environment:
      - ORTHANC_NAME=PHRTCowStudy

secrets:
  orthanc.json:
    file: orthanc.json

Do I miss something in the documentation and I still need to create a virtual environment for the pydicom pacakge? Or am I doing something else wrong?

Hi,

No packages are installed by default so you must build your own image.

Here’s an example Dockerfile for that.

HTH,

Aalin.