Good Morning,
I’m quite new to 3Dslicer and I’m trying to set up 3D slicer in a container so I can use python scripts in the Python environment of 3D Slicer. I follow then several guidelines and based myself on the slicer/slicer-notebook
container.
Correct me if I’m wrong but the executable python version needed is PythonSlicer
(linkhere and from the documentation, python scripts can be run from the terminal CLI.
Here is the dockerfile used to build my image:
# Linux env
FROM debian:buster
RUN apt update -y && apt upgrade -y
# RUN apt install -y \
# libpulse-dev \
# libglu1-mesa \
# libxi-dev \
# libxmu-dev \
# libglu1-mesa-dev \
# libnss3 \
# libglu1-mesa \
# libxcb-xinerama0 \
# libxkbcommon0
# Download 3DSlicer build
RUN apt install -y curl
# Current preview release (2021-10-15, rev30315)
ARG SLICER_DOWNLOAD_URL=https://download.slicer.org/bitstream/61690039342a877cb3d01245
RUN curl -JL "$SLICER_DOWNLOAD_URL" | tar xz -C /tmp && mv /tmp/Slicer* Slicer
# latest version
# https://download.slicer.org/bitstream/60add706ae4540bf6a89bf98
# Installing dependancies required by 3DSlicer runtime
RUN apt install -y \
libgl1-mesa-glx \
libxrender1 \
libpulse0 \
libpulse-mainloop-glib0 \
libnss3 \
libxcomposite1 \
libxcursor1 \
libfontconfig1 \
libxrandr2 \
libasound2 \
libglu1 \
libxi-dev \
libxcb-xinerama0 \
libxmu-dev \
libxkbcommon0
WORKDIR ${PWD}/Slicer
# copy utils files
COPY utils.py .
COPY tmp/masks.nii .
# RUN apt install -y libxrender1 libxcomposite-dev
CMD ["./Slicer","--launcher-verbose","--launcher-no-splash","--launch", "PythonSlicer", "utils.py"]
and here is the content of the utils.py file where I only try to load a segmentation:
import os
import sys
import slicer
import slicer.util
print("----Python version----")
print(sys.executable)
print("-----test library slicer----")
#Load a 3D image as segmentation
slicer.util.loadSegmentation("masks.nii")
Howerver, when I try to run the container I have several issue mainly due to the wrong python environnment:
- first the lunch python version is not
PythonSlicer
butpython-real
. - the
slicer.util
loading has a warning “No module named 'logic”. - the
slicer.util
library is loaded but impossible to access to theapp
file necessary for theslicer.util.loadSegmentation()
Here is the output:
No module named 'logic'
----Python version----
/Slicer/bin/./python-real
-----test library slicer----
Traceback (most recent call last):
File "utils.py", line 13, in <module>
slicer.util.loadSegmentation("masks.nii")
File "/Slicer/bin/Python/slicer/util.py", line 798, in loadSegmentation
return loadNodeFromFile(filename, 'SegmentationFile', {}, returnNode)
File "/Slicer/bin/Python/slicer/util.py", line 631, in loadNodeFromFile
from slicer import app
ImportError: cannot import name 'app'
I’m pretty sure it’s not a big issue? maybe some expert of the tool have some clues to help me to solve the problem.
Cheers,
Sébastien