Closed Dangku closed 2 months ago
got _imageingft import error
It looks like your install of Pillow is missing the text module (along with many others):
*** FREETYPE2 support not installed
How did you install Pillow?
freetype2 already installed, if i run with python 11, it shows FREETYPE2 support ok
# dpkg -l | grep freetype
ii libfreetype-dev:riscv64 2.13.2+dfsg-1+b4 riscv64 FreeType 2 font eng
ine, development files
ii libfreetype6:riscv64 2.13.2+dfsg-1+b4 riscv64 FreeType 2 font eng
ine, shared library files
(newenv) root@debian:~#
(newenv) root@debian:~# python3 -m PIL.report
--------------------------------------------------------------------
Pillow 10.4.0
Python 3.11.9 (main, Sep 4 2024, 21:57:31) [GCC 14.2.0]
--------------------------------------------------------------------
Python executable is /root/newenv/bin/python3
Environment Python files loaded from /root/newenv
System Python files loaded from /usr/local
--------------------------------------------------------------------
Python Pillow modules loaded from /root/newenv/lib/python3.11/site-packages/PIL
Binary Pillow modules loaded from /root/newenv/lib/python3.11/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
*** LITTLECMS2 support not installed
*** WEBP support not installed
*** WEBP Transparency support not installed
*** WEBPMUX support not installed
*** WEBP Animation support not installed
--- JPEG support ok, compiled for libjpeg-turbo 2.1.5
*** OPENJPEG (JPEG2000) support not installed
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
*** LIBTIFF support not installed
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
pillow is just normal install with pip command
(newenv) root@debian:~# pip3 install --upgrade pillow
also tried installing with --no-binary :all:, not work
If i installed pillow==10.3.0, this _imagingft import error not occur, but will got font resource error which not support by pillow 10.3.0
# python3 ssd1306_pillow_clock.py
Traceback (most recent call last):
File "/root/Adafruit_CircuitPython_SSD1306/examples/ssd1306_pillow_clock.py", line 53, in <module>
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 16)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 807, in truetype
return freetype(font)
^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 804, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 244, in __init__
self.font = core.getfont(
^^^^^^^^^^^^^
OSError: cannot open resource
It looks like you have multiple versions of Python installed. Instead of pip3 install ...
you should use python3 -m pip install ...
so that it uses the right version.
first test only python 3.12.5 installed, and error occured, then i reinstalled python 3.11.9 to test, and it worked well, python 3.9/3.10 + pillow 10,4.0 also worked well
Unless you plan to use multiple different Python versions, you don't need to test other versions. It's more helpful to just stick to the one(s) that you are concerned about.
What is the command that you will ultimately use to run ssd1306_pillow_clock.py? Is it python3 ssd1306_pillow_clock.py
?
I don't want to use multiple different python version, just trying to prove that it is related to this version of python 3.12.5, the first test is only python 3.12.5 version installed, and that's why i report this issue.
How will you ultimately run ssd1306_pillow_clock.py? python3 ssd1306_pillow_clock.py
? python3.12 ssd1306_pillow_clock.py
?
is this different? only python 3.12.5 installed, python3 link to python3.12.5.
# ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 10 Sep 4 22:45 /usr/bin/python3 -> python3.12
python3
and python3.12
might have been the same on your system, they might not have - I'm just trying to ensure that when you're installing Pillow, you're using the same command as when you're running your script.
Could you
python3 -m pip uninstall Pillow
python3 ssd1306_pillow_clock.py
and check that you get a different error, something like ImportError: cannot import name 'Image' from 'PIL'
. If you don't, go back to step 1 and try uninstalling Pillow again.python3 -m pip install Pillow --no-binary :all:
python3 ssd1306_pillow_clock.py
. If that works, excellent. If it doesn't work, please run python3 -m PIL.report
again and let us know the output this time.got No module 'PIL' error
after uninstall pillow
(myenv) root@debian:~# python3 -m pip uninstall Pillow
Found existing installation: pillow 10.4.0
Uninstalling pillow-10.4.0:
Would remove:
/root/myenv/lib/python3.12/site-packages/PIL/*
/root/myenv/lib/python3.12/site-packages/pillow-10.4.0.dist-info/*
Proceed (Y/n)? y
Successfully uninstalled pillow-10.4.0
(myenv) root@debian:~#
(myenv) root@debian:~# python3 ssd1306_pillow_clock.py
Traceback (most recent call last):
File "/root/ssd1306_pillow_clock.py", line 15, in <module>
from PIL import Image, ImageDraw, ImageFont
ModuleNotFoundError: No module named 'PIL'
(myenv) root@debian:~#
(myenv) root@debian:~# python3 -m pip install Pillow --no-binary :all:
Collecting Pillow
Using cached pillow-10.4.0-cp312-cp312-linux_riscv64.whl
Installing collected packages: Pillow
Successfully installed Pillow-10.4.0
(myenv) root@debian:~#
(myenv) root@debian:~# python3 ssd1306_pillow_clock.py
Traceback (most recent call last):
File "/root/ssd1306_pillow_clock.py", line 53, in <module>
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 16)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 834, in truetype
return freetype(font)
^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 831, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 215, in __init__
raise core.ex
File "/root/myenv/lib/python3.12/site-packages/PIL/ImageFont.py", line 59, in <module>
from . import _imagingft as core
ImportError: cannot import name '_imagingft' from 'PIL' (/root/myenv/lib/python3.12/site-packages/PIL/
__init__.py). Did you mean: '_imaging'?
(myenv) root@debian:~#
(myenv) root@debian:~# python3 -m PIL.report
--------------------------------------------------------------------
Pillow 10.4.0
Python 3.12.5 (main, Aug 22 2024, 13:11:09) [GCC 14.2.0]
--------------------------------------------------------------------
Python executable is /root/myenv/bin/python3
Environment Python files loaded from /root/myenv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /root/myenv/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /root/myenv/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
*** TKINTER support not installed
*** FREETYPE2 support not installed
*** LITTLECMS2 support not installed
*** WEBP support not installed
*** WEBP Transparency support not installed
*** WEBPMUX support not installed
*** WEBP Animation support not installed
--- JPEG support ok, compiled for libjpeg-turbo 2.1.5
*** OPENJPEG (JPEG2000) support not installed
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
*** LIBTIFF support not installed
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------
Using cached pillow-10.4.0-cp312-cp312-linux_riscv64.whl
Ah. This is interesting. This isn't actually one of the official wheels that we create.
Could you try uninstalling and then re-installing again, but this time with python3 -m pip install Pillow --no-binary :all: --no-cache-dir
? If you could include the output in your response again, that would be helpful.
(myenv) root@debian:~# python3 -m pip install Pillow --no-binary :all: Collecting Pillow Using cached pillow-10.4.0-cp312-cp312-linux_riscv64.whl
it's a mistake here that use cached binary, clean pillow cache and install with source again,
(myenv) root@debian:~# pip3 cache purge
Files removed: 176
(myenv) root@debian:~#
(myenv) root@debian:~# pip3 list | grep Pillow
(myenv) root@debian:~#
(myenv) root@debian:~# python3 -v -m pip install Pillow --no-binary :all:
...
(myenv) root@debian:~#
(myenv) root@debian:~# pip3 list | grep Pillow
(myenv) root@debian:~# pip3 list | grep pillow
pillow 10.4.0
(myenv) root@debian:~# python3 -m PIL.report
--------------------------------------------------------------------
Pillow 10.4.0
Python 3.12.5 (main, Aug 22 2024, 13:11:09) [GCC 14.2.0]
--------------------------------------------------------------------
Python executable is /root/myenv/bin/python3
Environment Python files loaded from /root/myenv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /root/myenv/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /root/myenv/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.4.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
*** LITTLECMS2 support not installed
*** WEBP support not installed
*** WEBP Transparency support not installed
*** WEBPMUX support not installed
*** WEBP Animation support not installed
--- JPEG support ok, compiled for libjpeg-turbo 2.1.5
*** OPENJPEG (JPEG2000) support not installed
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
*** LIBTIFF support not installed
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
(myenv) root@debian:~# python3 ssd1306_pillow_clock.py
now work with no error, thanks so much,
What did you do?
run Circuitython ssd1306 test example https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/blob/main/examples/ssd1306_pillow_clock.py
What actually happened?
got _imagingft import error
What are your OS, Python and Pillow versions?
it seems this error cause by python 3.12.5, I tested with python 3.11.9, 3.10 and 3.9, all things work fine.