Docker Container - failing to run the proper Python Environnment

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)
RUN curl -JL "$SLICER_DOWNLOAD_URL" | tar xz -C /tmp && mv /tmp/Slicer* Slicer

# latest version

# 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 \


# copy utils files
COPY tmp/masks.nii .

# RUN apt install -y libxrender1 libxcomposite-dev
CMD ["./Slicer","--launcher-verbose","--launcher-no-splash","--launch", "PythonSlicer", ""]

and here is the content of the file where I only try to load a segmentation:

import os
import sys

import slicer
import slicer.util

print("----Python version----")

print("-----test library slicer----")
#Load a 3D image as segmentation

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 but python-real.
  • the slicer.util loading has a warning “No module named 'logic”.
  • the slicer.util library is loaded but impossible to access to the app file necessary for the slicer.util.loadSegmentation()

Here is the output:

No module named 'logic'
----Python version----
-----test library slicer----
Traceback (most recent call last):
  File "", line 13, in <module>
  File "/Slicer/bin/Python/slicer/", line 798, in loadSegmentation
    return loadNodeFromFile(filename, 'SegmentationFile', {}, returnNode)
  File "/Slicer/bin/Python/slicer/", 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. :slight_smile:


This is correct. The executable is python-real. The Slicer or PythonSlicer launcher sets up the virtual Python environment and executes python-real.

PythonSlicer is a Python interpreter, which you can use to have access to basic Python features without installing a Python distribution. You can use this to install packages, use standard Python packages, and even some Slicer features that does not require a running Slicer application.

For most actual data processing you need Slicer modules, which are instantiated by the Slicer application. You can start the Slicer application, by specifying SlicerApp-real instead of PythonSlicer as --launch argument. Or you can simply remove "--launch", "PythonSlicer", to run the default executable, which is the Slicer application.

1 Like

Alright thanks for this precious information, it makes then perfectly sense to have python-real running.
Since I need slicer features requiring the application to run, I will select the second option.

1 Like