tabreturn / thonny-py5mode

A py5 plug-in for Thonny
Do What The F*ck You Want To Public License
23 stars 8 forks source link

cannot import name 'ImageTk' from 'PIL' on Fedora40 #62

Closed plesiosaur closed 4 weeks ago

plesiosaur commented 1 month ago

Hi. When I use a Python virtual environment, I can get Thonny installed in it and the thonny-py5mode plugin works. However, when I've deactivated the virtual environment and try to install normally, your plugin doesn't load correctly for me. This is on Fedora 40 Compiz-Mate. When Thonny opens up, there is no "py5" menu in the menubar. The error output is:

10:48:23.570 [MainThread] INFO thonny.workbench: Start loading plugins 10:48:23.665 [MainThread] ERROR thonny.workbench: Failed loading plugin 'thonnycontrib.thonny-py5mode' Traceback (most recent call last): File "/usr/lib/python3.12/site-packages/thonny/workbench.py", line 409, in _load_plugins_from_path m = importlib.import_module(module_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/importlib/init.py", line 90, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File "<frozen importlib._bootstrap>", line 1360, in _find_and_load File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 935, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 995, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "/home/vos/.config/Thonny/plugins/lib/python3.12/site-packages/thonnycontrib/thonny-py5mode/init.py", line 33, in from .py5colorpicker.tkcolorpicker import modeless_colorpicker File "/home/vos/.config/Thonny/plugins/lib/python3.12/site-packages/thonnycontrib/thonny-py5mode/py5colorpicker/tkcolorpicker/init.py", line 21, in from .colorpicker import ColorPicker, askcolor, modeless_colorpicker File "/home/vos/.config/Thonny/plugins/lib/python3.12/site-packages/thonnycontrib/thonny-py5mode/py5colorpicker/tkcolorpicker/colorpicker.py", line 24, in from PIL import ImageTk ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib64/python3.12/site-packages/PIL/init.py) 10:48:23.666 [MainThread] INFO thonny.workbench: Done loading plugins

2 lines up from here, it mentions the file /usr/lib64/python3.12/site-packages/PIL/init.py Well, when I open that file and look for ImageTk myself, it's not in the list of modules. Here is the top part of that file, so you can see what I see.

"""Pillow (Fork of the Python Imaging Library)

Pillow is the friendly PIL fork by Jeffrey A. Clark and contributors. https://github.com/python-pillow/Pillow/

Pillow is forked from PIL 1.1.7.

PIL is the Python Imaging Library by Fredrik Lundh and contributors. Copyright (c) 1999 by Secret Labs AB.

Use PIL.version for this Pillow version.

;-) """

from future import annotations

from . import _version

# VERSION was removed in Pillow 6.0.0. # PILLOW_VERSION was removed in Pillow 9.0.0. # Use version instead. version = _version.version del _version

_plugins = [ "BlpImagePlugin", "BmpImagePlugin", "BufrStubImagePlugin", "CurImagePlugin", "DcxImagePlugin", "DdsImagePlugin", "EpsImagePlugin", "FitsImagePlugin", "FliImagePlugin", "FpxImagePlugin", "FtexImagePlugin", "GbrImagePlugin", "GifImagePlugin", "GribStubImagePlugin", "Hdf5StubImagePlugin", "IcnsImagePlugin", "IcoImagePlugin", "ImImagePlugin", "ImtImagePlugin", "IptcImagePlugin", "JpegImagePlugin", "Jpeg2KImagePlugin", "McIdasImagePlugin", "MicImagePlugin", "MpegImagePlugin", "MpoImagePlugin", "MspImagePlugin", "PalmImagePlugin", "PcdImagePlugin", "PcxImagePlugin", "PdfImagePlugin", "PixarImagePlugin", "PngImagePlugin", "PpmImagePlugin", "PsdImagePlugin", "QoiImagePlugin", "SgiImagePlugin", "SpiderImagePlugin", "SunImagePlugin", "TgaImagePlugin", "TiffImagePlugin", "WebPImagePlugin", "WmfImagePlugin", "XbmImagePlugin", "XpmImagePlugin", "XVThumbImagePlugin", ]

What packages are installed? Here is the relevant stuff, I think.

$dnf list python3 python3-tkinter thonny Last metadata expiration check: 0:22:01 ago on Thu 15 Aug 2024 10:47:16 AM EDT. Installed Packages python3.x86_64 3.12.4-1.fc40 python3-tkinter.x86_64 3.12.4-1.fc40 thonny.noarch 4.1.4-2.fc40

villares commented 1 month ago

Thank you for your report @plesiosaur, I hope this issue might help us understand better what is going on and how to fix it!

When you say "install normally" (without a virtual environment) what method are you using? Thonny proposes several methods (I'm wary of the 3rd party distributions because they might be old):

image

I'm on Manjaro and I have been using previously the https://thonny.org/installer-for-linux script method.

I have also recently installed Thonny using pipx install thonny (you'd have probably to install pipx) it is kind of a way of creating automatically a virtual environment.

Have you tried this or another method?

plesiosaur commented 1 month ago

Thanks for the quick response. The way I installed Thonny was...

sudo dnf install thonny

...then I ran the command...

thonny

...and went to Tools --> Manage plug-ins, did a search for py5, selected thonny-py5mode, and clicked Install. When it was done, I quit Thonny and restarted it. Still, the py5 menu is absent from the menubar. When I return to the plugin page, the buttons are for Upgrade, Uninstall, "...", and Close.

Versions of my software (x86_64, Fedora40 Compiz-Mate) Python 3.12.4 Thonny 4.1.4 thonny-py5mode 0.4.7a0 py5 0.10.2a0 openjdk 21.0.4

Next week I will try some other installation methods you pointed out. I am running this Linux in a Virtualbox VM so that it's easy to jump back to an old snapshot before I installed a particular thing and try it another way.

villares commented 1 month ago

The versions you have shown are the most recent and I was happy to learn this about the Fedora packaging! I'm afraid something else is not going well :(

It looks like ImageTK lets Pillow (the modern version of PIL) work with tkinter (https://pillow.readthedocs.io/en/stable/reference/ImageTk.html) and I was reminded recently that on some Linux distributions tkinter (that is part of the Python standard library) does not come installed with the system Python. Could you try something like sudo dnf install python-tkinter, and then reinstall Pillow maybe to see if it helps?

plesiosaur commented 4 weeks ago

Without specifically installing these, I have them:

$ dnf list python3-pillow python3-tkinter Installed Packages python3-pillow.x86_64 10.3.0-1.fc40 python3-tkinter.x86_64 3.12.4-1.fc40

Something I learned might be important to have is python3-pillow-tk, thanks to this page: https://github.com/jepler/cropgui/issues/89

My system didn't have that package, so I installed it with...

$ sudo dnf install python3-pillow-tk

$ dnf list python3-pillow-tk Installed Packages python3-pillow-tk.x86_64 10.3.0-1.fc40

That fixed my issue. Now in Thonny I have the py5 menu in the menubar.

Thanks for the suggestions along the way.