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

**URL:** <https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448>\
**Category:** Support\
**Created:** [November 5, 2020, 3:42pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448 "2020-11-05T15:42:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [November 5, 2020, 3:42pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/1 "2020-11-05T15:42:52Z")

</div>

Hi all,

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

```python
>>> 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?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [November 5, 2020, 4:55pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/2 "2020-11-05T16:55:27Z")

</div>

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.

> <https://github.com/Slicer/Slicer/blob/v4.11.20200930/SuperBuild/External_python-dicom-requirements.cmake#L45-L52>

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [November 6, 2020, 4:55pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/3 "2020-11-06T16:55:34Z")

</div>

Hi, @jamesobutler.

> [@jamesobutler](#):
>
> Does `from PIL import Image` not work from a fresh download of the current Slicer Stable?

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

```bash
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:

```python-traceback
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

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 17, 2020, 4:14pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/4 "2020-11-17T16:14:31Z")

</div>

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

> <https://github.com/Slicer/SlicerDocker/blob/275973c21dc70822ac0f70495baa6fc89b86a30a/slicer-notebook/install.sh#L56-L61>

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [November 17, 2020, 5:13pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/5 "2020-11-17T17:13:30Z")

</div>

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

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

```

### Before

```auto
./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

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

```

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [December 10, 2020, 9:21am UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/6 "2020-12-10T09:21:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [February 15, 2021, 10:57pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/7 "2021-02-15T22:57:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [February 23, 2021, 4:13pm UTC](https://discourse.slicer.org/t/slicer-4-11-20200930-cant-import-pip-installed-pillow-on-linux/14448/8 "2021-02-23T16:13:59Z")

</div>

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](https://github.com/Slicer/Slicer/issues/5474)
