New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault on import when gi is imported #5637
Comments
So gi is https://pypi.org/project/PyGObject/ If I take our arch Docker image, and add this in, there is no problem. |
At the start of ImageOps, we have 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 from gi.repository import Gtk
import functools
import operator
import re |
This code works for me. (assuming there is also |
Actually, this is wrong. from gi.repository import Gtk
from PIL import ImageOps These 2 lines cause segfault. No Image import needed. |
This comment has been minimized.
This comment has been minimized.
On 8.3.x branch which I have: https://github.com/python-pillow/Pillow/tree/8.3.x from gi.repository import Gtk
from PIL import _imagingft This c file causes segfault. |
I bet you're getting a shared library conflict with freetype or one of the other things in the font stack. |
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 |
Swapping imports does not cause segmentation fault though. Does this mean gtk has some workaround/fallback for this conflict which Pillow does not? |
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. |
While my last attempt to replicate was through |
How did you actually install Pillow? |
Using pip, from pypi |
Thanks. If you're interested, a simpler alternative to installing through |
I saw a similar conflict with matplotlib: import matplotlib.pyplot as plt
from PIL import ImageDraw will cause a segmentation fault, or swap the lines (i.e. import PIL first) and it works OK. |
Yeah, I have this happening on my Debian Sid machine right now (Pillow 8.3.1, installed via
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 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. |
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 |
It worked: $ 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" |
@nulano yes, this wheel fixes my crash. Thank you. |
Thanks, I also encountered a similar issue with I could reduce it down to the code below: import gi
from gi.repository import Gtk, Gdk, GdkPixbuf
from PIL import ImageDraw which would segfault. Modifying this excerpt by importing import gi
from PIL import ImageDraw
from gi.repository import Gtk, Gdk, GdkPixbuf With |
Version 8.3.1 may segfault when gi.Gdk is imported before PIL. This will be fixed in Pillow==8.4.0. See: python-pillow/Pillow#5637 (comment)
Version 8.3.1 may segfault when gi.Gdk is imported before PIL. This will be fixed in Pillow==8.4.0. See: python-pillow/Pillow#5637 (comment)
Pillow 8.3.2 has just been released with the fix for this. |
What did you do?
What did you expect to happen?
No errors
What actually happened?
What are your OS, Python and Pillow versions?
EDIT: shorter code causing segfault
The text was updated successfully, but these errors were encountered: