Slicer-4.11.20200930: Can't import pip-installed Pillow on Linux

Hi all,

I can’t run the line below in the current Linux stable (and preview) release, after running pip_install('Pillow'):

>>> from PIL import Image
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/fernando/opt/Slicer-4.11.20200930-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: /home/fernando/opt/Slicer-4.11.20200930-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so: ELF load command address/offset not properly aligned
>>> 

Do you know what could be happening?

Does from PIL import Image not work from a fresh download of the current Slicer Stable?

You shouldn’t have to install Pillow as it is is already installed as part of the External_python-dicom-requirements project.

1 Like

Hi, @jamesobutler.

Correct, it doesn’t. Here is a (hopefully) MWE:

curl --silent --output slicer_stable_linux.tar.gz --location https://download.slicer.org/bitstream/1341035
tar zxf slicer_stable_linux.tar.gz
Slicer-4.11.20200930-linux-amd64/Slicer --ignore-slicerrc --no-splash --no-main-window -c "from PIL import Image"

Output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/Slicer-4.11.20200930-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: /tmp/Slicer-4.11.20200930-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so: ELF load command address/offset not properly aligned
Info: In /work/Stable/Slicer-0/Libs/MRML/Core/vtkMRMLScene.cxx, line 316
vtkMRMLScene (0x2bc2420): vtkMRMLScene::Clear

I had to apply this fix in the Slicer docker image to resolve this error:

1 Like

To address the problem with the latest stable, the following should be done:

cd Slicer-4.11.20200930-linux-amd64
./bin/PythonSlicer -c "from slicer.util import pip_install; pip_install('--upgrade pillow --force-reinstall')"

Before

./bin/PythonSlicer -c "import PIL; print(PIL.__version__); from PIL import Image"
7.2.0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jcfr/Downloads/Slicer-4.11.0-2020-09-30-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: /home/jcfr/Downloads/Slicer-4.11.0-2020-09-30-linux-amd64/lib/Python/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-x86_64-linux-gnu.so: ELF load command address/offset not properly aligned

After

./bin/PythonSlicer -c "import PIL; print(PIL.__version__); from PIL import Image"
8.0.1
1 Like

This is also happening with scipy. Shall I open an issue about this on GitHub?

The same workaround will work for scipy. It would be great if you could open an issue.

I just saw this. I suppose this can be tracked in Importing the numpy C-extensions failed. [slicer 4.11.20200930, archlinux] · Issue #5474 · Slicer/Slicer · GitHub