You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Segmentation fault on import when gi is imported #5637
Are you able to test this locally, and see if it is not ImageOps causing the problem directly, but actually functools, operator or re? Maybe this crash can be replicated without importing Pillow at all. Does this code load for you?
This code works for me. (assuming there is also from PIL import Image before that)
I only get segfault behaviour when I import Image, then gi, then ImageOps.
Changing order or removing any step removes segfault.
To unpack a bit -- your gtk is going to have some associated versions of the freetype/raqm libs, and we're not necessarily going to ship the same ones in our binary wheels. Since you're hosting this in the same process, you need to have one version of the libraries, and that's going to be whatever is on your system that GTK is linking to. (assuming that your gtk is using system packages, because the wheels would be immense otherwise).
So try building Pillow from source --activate your virtualenv or whatever, clone the source and check out 8.3.1. Then make install in the pillow directory should give you something that works.
So try building Pillow from source --activate your virtualenv or whatever, clone the source and check out 8.3.1. Then make install in the pillow directory should give you something that works.
Thanks. If you're interested, a simpler alternative to installing through make should be to use pip without binary wheels - pip install Pillow --no-binary :all:
will cause a segmentation fault, or swap the lines (i.e. import PIL first) and it works OK.
(OS: Ubuntu 20.04, Python: 3.8.10, pip: 21.2.2, Matplotlib: 3.4.2, Pillow: 8.3.1)
I bet you're getting a shared library conflict with freetype or one of the other things in the font stack.
Yeah, I have this happening on my Debian Sid machine right now (Pillow 8.3.1, installed via pip3). It seems to be segfaulting in fribidi_load() (when running mcomix3).
Program received signal SIGSEGV, Segmentation fault.
r0x00007ffff27c196a in load_fribidi ()
from /home/wyatt/.local/lib/python3.9/site-packages/PIL/_imagingft.cpython-39-x86_64-linux-gnu.so
Seems like swapping import ordering is working here, too, but I don't think that's really a good solution since there's still some incorrect behavior happening somewhere that's not fundamentally fixed. Also, it's not very "pythonic" to segfault if import ordering is switched up :)
Additionally, the old version of Pillow I had (8.0.1) does not cause this segfault regardless of import order. I think that is from before Fribidi was introduced to the stack, though.
$ python -c "from gi.repository import Gtk;from PIL import _imagingft"<string>:1: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
Older Pillow:
$ python -c "from gi.repository import Gtk;from PIL import _imagingft"<string>:1: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
[1] 708711 segmentation fault (core dumped) python -c "from gi.repository import Gtk;from PIL import _imagingft"
Activity
radarhere commentedon Jul 26, 2021
So gi is https://pypi.org/project/PyGObject/
If I take our arch Docker image, and add this in, there is no problem.
radarhere commentedon Jul 26, 2021
At the start of ImageOps, we have
Pillow/src/PIL/ImageOps.py
Lines 20 to 22 in 55cec2a
Are you able to test this locally, and see if it is not ImageOps causing the problem directly, but actually
functools,operatororre? Maybe this crash can be replicated without importing Pillow at all. Does this code load for you?Fogapod commentedon Jul 26, 2021
This code works for me. (assuming there is also
from PIL import Imagebefore that)I only get segfault behaviour when I import Image, then gi, then ImageOps.
Changing order or removing any step removes segfault.
Fogapod commentedon Jul 26, 2021
Actually, this is wrong.
These 2 lines cause segfault. No Image import needed.
Fogapod commentedon Jul 26, 2021
Fogapod commentedon Jul 26, 2021
On 8.3.x branch which I have: https://github.com/python-pillow/Pillow/tree/8.3.x
There is ImageDraw import which imports ImageFont which imports _imagingft.
This c file causes segfault.
wiredfool commentedon Jul 26, 2021
I bet you're getting a shared library conflict with freetype or one of the other things in the font stack.
wiredfool commentedon Jul 26, 2021
To unpack a bit -- your gtk is going to have some associated versions of the freetype/raqm libs, and we're not necessarily going to ship the same ones in our binary wheels. Since you're hosting this in the same process, you need to have one version of the libraries, and that's going to be whatever is on your system that GTK is linking to. (assuming that your gtk is using system packages, because the wheels would be immense otherwise).
So try building Pillow from source --activate your virtualenv or whatever, clone the source and check out 8.3.1. Then
make installin the pillow directory should give you something that works.Fogapod commentedon Jul 26, 2021
Swapping imports does not cause segmentation fault though. Does this mean gtk has some workaround/fallback for this conflict which Pillow does not?
radarhere commentedon Jul 26, 2021
That import was removed by #5615. So if it helps you at all, that will be removed from ImageOps in the next release of Pillow, on October 15th.
radarhere commentedon Jul 26, 2021
While my last attempt to replicate was through
make- installing through pip instead does trigger the segfault.radarhere commentedon Jul 29, 2021
How did you actually install Pillow?
Fogapod commentedon Jul 29, 2021
Using pip, from pypi
radarhere commentedon Jul 29, 2021
Thanks. If you're interested, a simpler alternative to installing through
makeshould be to use pip without binary wheels -pip install Pillow --no-binary :all:explode commentedon Aug 1, 2021
I saw a similar conflict with matplotlib:
will cause a segmentation fault, or swap the lines (i.e. import PIL first) and it works OK.
(OS: Ubuntu 20.04, Python: 3.8.10, pip: 21.2.2, Matplotlib: 3.4.2, Pillow: 8.3.1)
wyatt8740 commentedon Aug 2, 2021
Yeah, I have this happening on my Debian Sid machine right now (Pillow 8.3.1, installed via
pip3). It seems to be segfaulting infribidi_load()(when running mcomix3).Seems like swapping import ordering is working here, too, but I don't think that's really a good solution since there's still some incorrect behavior happening somewhere that's not fundamentally fixed. Also, it's not very "pythonic" to segfault if
importordering is switched up :)Additionally, the old version of Pillow I had (8.0.1) does not cause this segfault regardless of import order. I think that is from before Fribidi was introduced to the stack, though.
nulano commentedon Aug 2, 2021
I managed to reproduce this on the wheel builder and made a potential fix that fixes the segfault.
@Fogapod @wyatt8740 Could you please test with the wheel from https://github.com/nulano/pillow-wheels/actions/runs/1091871497 (download the
wheelsartifact, unzip, and install the wheel withpython -m pip install Pillow-8.4.0.dev0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl, using Python 3.9 x64)?Fogapod commentedon Aug 3, 2021
It worked:
Older Pillow:
wyatt8740 commentedon Aug 3, 2021
@nulano yes, this wheel fixes my crash. Thank you.
cydanil commentedon Aug 16, 2021
Thanks, I also encountered a similar issue with
pillow==8.3.1andPyGObject==3.40.1.I could reduce it down to the code below:
which would segfault.
Modifying this excerpt by importing
pillowfirst resolved the issue:With
pillow==8.3.0, the order does not matter and the code runs fine.The wheel linked above also resolves the issue in my case!
Pin Pillow version
Pin Pillow version
radarhere commentedon Sep 2, 2021
Pillow 8.3.2 has just been released with the fix for this.