-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Problem with using ImageTk on Cygwin #5795
Comments
Hi. Let me ask this question - does tkinter work fine by itself? import tkinter
root = tkinter.Tk()
root.mainloop() |
Yes, the following narrowed-down script works well: import tkinter
from PIL import Image, ImageTk
image = Image.new('RGB', (100, 100))
tk = tkinter.Tk()
canvas = tkinter.Canvas(tk)
canvas.pack()
#photoimage = ImageTk.PhotoImage(image)
#canvas.create_image((0, 0),
# image=photoimage,
# anchor='nw',
#)
tk.mainloop() This script is based on the It is the line |
One of the guidelines for reporting bugs on Cygwin is this:
Have you done that, and does anything in there look like it could pose a problem? From your traceback in the reproducer repository, it looks like the problem is with the line If |
OK, the diagnostic information you asked for is provided in https://github.com/friedrichromstedt/bughunting-02/tree/v2021-10-26_1#diagnostic-information-26-october-2021. Notice that I am referring to the tagged version to ensure permanent links. The output of Importing |
Interesting. I'm guessing that Does import tkinter
tkinter.__file__ fail? |
None of these fails. See: $ python
Python 3.8.10 (default, May 20 2021, 11:41:59)
[GCC 10.2.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import _tkinter_finder
>>> and $ python
Python 3.8.10 (default, May 20 2021, 11:41:59)
[GCC 10.2.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> tkinter.__file__
'/usr/lib/python3.8/tkinter/__init__.py' The two modules/packages can also be imported in the same |
Some more observations:
So maybe Pillow is not the actual culprit. I've also downgraded Tcl/Tk from recent 8.6.11 to 8.6.8 in the abovementioned section, to no avail. However, since Pillow is the piece of code which yields the exception, I have the hope that some helpful conclusion can be drawn here. |
Any further ideas how to track down this issue? |
Lines 54 to 55 in a215f72
and Lines 380 to 397 in 95cff6e
look to be the only places that could fail on import. import tkinter
tk = tkinter.Tk()
canvas = tkinter.Canvas(tk)
canvas.pack()
photoimage = tkinter.PhotoImage(file="/path/to/image.png")
canvas.create_image((0, 0), image=photoimage, anchor='nw')
tk.mainloop() works fine. I'm not sure how to check further what's going on beyond this. An interesting comment — Lines 224 to 230 in 95cff6e
— suggests that this is one of the times that "Cygwin uses Windows linking semantics" is relevant: I suspect Pillow is currently trying to import symbols defined in the Tcl/Tk shared libraries from Python's _tkinter shared library. It would be interesting to have the Cygwin build of Pillow use the Windows code path and see if that fixes the issue. |
Edit: I didn't read the page closely enough: the macro may be defined based on the selected compile configuration. |
Apparently Cygwin does sometimes define $ echo | gcc -x c - -E -dM | grep -i WIN
#define __WINT_MAX__ 0xffffffffU
#define __WINT_MIN__ 0U
#define __SIZEOF_WINT_T__ 4
#define __CYGWIN__ 1
#define __WINT_TYPE__ unsigned int
#define __WINT_WIDTH__ 32 I don't think that flag got passed in any of the Pillow builds mentioned in the reproduction repository. |
@friedrichromstedt, do the changes suggested in #5807 fix the problem for you? |
The branch https://github.com/DWesl/Pillow/tree/tkimaging-on-cygwin (29b9239) referenced in #5807 solved the problem on my machine. Detailed information about my proceeding is available on https://github.com/friedrichromstedt/bughunting-02/tree/v2021-11-05_2#proposal-of-a-fix-from-upstream. Thanks a lot for all the work which has been spent solving this issue. I noticed that the version of the branch I used (29b9239) is one commit behind the current https://github.com/DWesl/Pillow/tree/tkimaging-on-cygwin. Shall I test once more? |
The latest commit should just skip a test that won't work on Cygwin. Is whatever code inspired your test case working now? |
I noticed that even with DWesl@29b9239 the selftests pass. You can find the logs in https://github.com/friedrichromstedt/bughunting-02/blob/v2021-11-05_2/Logs2/b01%20make%20install.txt, context in https://github.com/friedrichromstedt/bughunting-02/tree/v2021-11-05_2#proposal-of-a-fix-from-upstream.
Yes! I tested carefully, so it needed some time. Thanks again! |
I am told that at some point the recommended way to run Pillow's tests changed from |
Yes, There's some more info in https://github.com/python-pillow/Pillow/blob/main/Tests/README.rst * |
From what I see on #5807 you already tested diligently. From your comment on 5 Nov 2021 I gather that you also did the X-related tests? Should I test once more on my machine? I am starting the X server through a Cygwin-supplied shortcut file (which is invoking |
Probably once through the Pillow test suite is enough. I also use
Thank you for testing. |
While attempting to use
ImageTk
on Cygwin (64-bit, Windows 10, Python 3.8), I ran into an unhandled Exception. Just attempting to show some black square Pillow Image using a tkinterCanvas
causes this failure. I've tried several versions of Pillow, from8.4.0
down to5.4.1
, all with the same result.Further description of the dysfunction including a minimal example script can be found at https://github.com/friedrichromstedt/bughunting-02. This repo provides a summary along with detailed information on my work regarding the subject.
I've reported to Cygwin upstream https://sourceware.org/pipermail/cygwin/2021-October/249643.html, but up to now this did not lead to a solution. It might be that the problem is rooted somewhere outside of Pillow, but I would appreciate any pointer.
The text was updated successfully, but these errors were encountered: