Skip to content
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

Error: cannot import name '_imagingft' #7949

Closed
SPIN04 opened this issue Apr 6, 2024 · 19 comments
Closed

Error: cannot import name '_imagingft' #7949

SPIN04 opened this issue Apr 6, 2024 · 19 comments
Labels
Installation Usually a problem with … Linux

Comments

@SPIN04
Copy link

SPIN04 commented Apr 6, 2024

i'm trying to manipulate the image adding a text overlay, the overlay of image work fine but the text dosn't work giving me this error
Error: cannot import name '_imagingft' from 'PIL' (/home/spino/.local/lib/python3.10/site-packages/PIL/init.py)

also during the installation i got a bunch of warnign

spino@api:~/cam$ pypy3 -m pip install --upgrade Pillow
Defaulting to user installation because normal site-packages is not writeable
Collecting Pillow
  Downloading pillow-10.3.0.tar.gz (46.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.6/46.6 MB 819.3 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package Pillow produced metadata for project name unknown. Fix your #egg=Pillow fragments.
Discarding https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d (from https://pypi.org/simple/pillow/) (requires-python:>=3.8): Requested unknown from https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d has inconsistent name: filename has 'pillow', but metadata has 'unknown'
  Downloading pillow-10.2.0.tar.gz (46.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.2/46.2 MB 829.4 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
  WARNING: Generating metadata for package Pillow produced metadata for project name unknown. Fix your #egg=Pillow fragments.
Discarding https://files.pythonhosted.org/packages/f8/3e/32cbd0129a28686621434cbf17bb64bf1458bfb838f1f668262fefce145c/pillow-10.2.0.tar.gz#sha256=e87f0b2c78157e12d7686b27d63c070fd65d994e8ddae6f328e0dcf4a0cd007e (from https://pypi.org/simple/pillow/) (requires-python:>=3.8): Requested unknown from https://files.pythonhosted.org/packages/f8/3e/32cbd0129a28686621434cbf17bb64bf1458bfb838f1f668262fefce145c/pillow-10.2.0.tar.gz#sha256=e87f0b2c78157e12d7686b27d63c070fd65d994e8ddae6f328e0dcf4a0cd007e has inconsistent name: filename has 'pillow', but metadata has 'unknown'
  Downloading Pillow-10.1.0.tar.gz (50.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.8/50.8 MB 864.3 kB/s eta 0:00:00
  Installing build dependencies ... \^canceled
ERROR: Operation cancelled by user
^[[A^[[Aspino@apisudo apt install pypy3e Pillow
[sudo] password for spino:
sudo: a password is required
spino@api:~/cam$ pip uninstall pillow
WARNING: Skipping pillow as it is not installed.
spino@api:~/cam$ python3 test.py
Traceback (most recent call last):
  File "/home/spino/cam/test.py", line 1, in <module>
    import PIL
ModuleNotFoundError: No module named 'PIL'

then i installed pillow with pip install pillow==10.3.0

Defaulting to user installation because normal site-packages is not writeable
Collecting pillow==10.3.0
  Using cached pillow-10.3.0-cp310-cp310-linux_armv7l.whl
Installing collected packages: pillow
Successfully installed pillow-10.3.0
spino@api:~/cam$ python3 test.py
<module 'PIL' from '/home/spino/.local/lib/python3.10/site-packages/PIL/__init__.py'>

so i tried the code to put the overlay and the error showed up

What are your OS, Python and Pillow versions?

  • OS: Distributor ID: Ubuntu
    Description: Ubuntu 22.04.4 LTS
    Release: 22.04
    Codename: jammy

  • Python: 3.10.12

  • Pillow: 10.3.0

spino@api:~/cam$ python3 -m PIL.report
--------------------------------------------------------------------
Pillow 10.3.0
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
--------------------------------------------------------------------
Python executable is /usr/bin/python3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/spino/.local/lib/python3.10/site-packages/PIL
Binary Pillow modules loaded from /home/spino/.local/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.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.2
*** OPENJPEG (JPEG2000) support not installed
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.11
--- LIBTIFF support ok, loaded 4.3.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------
main.py
from log import write_to_log as log
from camera_util import scatta, overlay_barre,overlay_testo

import time
start_time = time.time()
log("inizio scatto")

try:
    log("dentro try",'debug')
    scatta()
    log("dopo scatto",'debug')
except Exception as e:
    log(f"errore{e}","fatal")
    
log("fine scatto")

log("inizio set overlay barre")
overlay_barre()
log("fine set overlay barre")

log("inizio set overlay testo")
overlay_testo("casela vista valle","center","bottom")
log("fine set overlay testo")


end_time = time.time()

execution_time = end_time - start_time
print("Tempo di esecuzione:", execution_time, "secondi")


camera_util.py

from PIL import Image, ImageStat, ImageDraw, ImageFont

from time import sleep
from picamera import PiCamera
from fractions import Fraction

def scatta():
    
    try:
        camera = PiCamera()
        camera.resolution = (1024, 768)
        
        
        camera.start_preview(fullscreen=False)
        camera.framerate=1
        camera.sensor_mode=3
        # Camera warm-up time
        sleep(5)
        camera.capture('pictures/foo.jpg')

        
    finally:
        # Assicurati di chiudere correttamente la fotocamera anche in caso di errore
        camera.stop_preview()
        camera.close()
        
def overlay_barre():

    # Carica l'immagine di base
    base_image = Image.open("pictures/foo.jpg")

    # Carica l'immagine monocromatica
    monochrome_image = Image.open("pictures/Barre.png")

    # Ottieni le dimensioni dell'immagine di base
    base_width, base_height = base_image.size

    # Ridimensiona l'immagine monocromatica alle dimensioni dell'immagine di base
    monochrome_resized = monochrome_image.resize((base_width, 30))

    # Sovrapposizione dell'immagine monocromatica nella parte superiore dell'immagine di base
    base_image.paste(monochrome_resized, (0, 0))
    base_image.paste(monochrome_resized, (0, base_height - 20))

    # Salva l'immagine con la sovrapposizione
    base_image.save("pictures/output_image.jpg")
    


def overlay_testo(text: str, x_position: str, y_position: str) -> Image.Image:
    """
    Creates a text overlay on the given image.

    Args:
    - text (str): The text content to overlay.
    - x_position (str): The position of the text overlay on the x-axis (left, center, right).
    - y_position (str): The position of the text overlay on the y-axis (top, bottom).

    Returns:
    - Image.Image: The image with the text overlay.
    """
    try:
        # Open the image
        with Image.open("pictures/output_image.jpg") as img:
            # Get image dimensions
            image_width, image_height = img.size

            # Create font and calculate text size
            font_size = 24  # Change as needed
            font = ImageFont.truetype("/font/COMICSANS.TTF", font_size)
            text_width, text_height = font.getsize(text)

            # Calculate x position
            if x_position == "left":
                x = 10
            elif x_position == "center":
                x = (image_width - text_width) // 2
            elif x_position == "right":
                x = image_width - text_width - 10
            else:
                raise ValueError("Invalid x position. Position must be one of: left, center, right")

            # Calculate y position
            if y_position == "top":
                y = 10
            elif y_position == "bottom":
                y = image_height - text_height - 10
            else:
                raise ValueError("Invalid y position. Position must be one of: top, bottom")

            # Add text overlay
            draw = ImageDraw.Draw(img)
            draw.text((x, y), text, fill="white", font=font)

            return img

    except Exception as e:
        print("Error:", e)
        return None

# Example usage:
# create_text_overlay("Hello, Pillow!", "center", "bottom")
@radarhere
Copy link
Member

Hi. You are missing a dependency, as you are building from source. Please try the following

python3 -m pip uninstall Pillow
sudo apt-get install libfreetype6-dev
python3 -m pip install Pillow

For your pypy3 warnings, I would suggest you uninstall Pillow, upgrade pypy3's pip and try again - but it's not relevant if you are ultimately running python3 instead.

@radarhere radarhere added Installation Usually a problem with … Linux labels Apr 6, 2024
@nulano
Copy link
Contributor

nulano commented Apr 6, 2024

pypy3 -m pip install --upgrade Pillow
apt install pypy3e Pillow
pip uninstall pillow
then i installed pillow with pip install pillow==10.3.0
python3 -m PIL.report

You are mixing a bunch of different tools here.
Are you trying to use Pillow with pypy3 or /usr/bin/python3?

You should avoid using pip directly because it is not clear which Python version will be used. Instead use pypy3 -m pip or python3 -m pip as radarhere showed above.

Using cached pillow-10.3.0-cp310-cp310-linux_armv7l.whl

What is your CPU architecture? I don't know if anyone has tried installing Pillow with PyPy on arm before. Edit: Actually, arm64 does seem to be covered by our CI, but not 32-bit arm.

@SPIN04
Copy link
Author

SPIN04 commented Apr 6, 2024

spino@api:/cam$ python3 -m pip uninstall Pillow
Found existing installation: pillow 10.3.0
Uninstalling pillow-10.3.0:
Would remove:
/home/spino/.local/lib/python3.10/site-packages/PIL/*
/home/spino/.local/lib/python3.10/site-packages/pillow-10.3.0.dist-info/*
Proceed (Y/n)? y
Successfully uninstalled pillow-10.3.0
spino@api:
/cam$ sudo apt-get install libfreetype6-dev
[sudo] password for spino:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libfreetype6-dev is already the newest version (2.11.1+dfsg-1ubuntu0.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
spino@api:/cam$ python3 -m pip install Pillow
Defaulting to user installation because normal site-packages is not writeable
Collecting Pillow
Using cached pillow-10.3.0-cp310-cp310-linux_armv7l.whl
Installing collected packages: Pillow
Successfully installed Pillow-10.3.0
spino@api:
/cam$ python3 main.py
[2024-04-06 15:23:36.207552] [INFO] [main.py] [6] inizio scatto
[2024-04-06 15:23:36.211329] [DEBUG] [main.py] [9] dentro try
[2024-04-06 15:23:48.822373] [DEBUG] [main.py] [11] dopo scatto
[2024-04-06 15:23:48.825461] [INFO] [main.py] [15] fine scatto
[2024-04-06 15:23:48.830057] [INFO] [main.py] [17] inizio set overlay barre
[2024-04-06 15:23:49.165905] [INFO] [main.py] [19] fine set overlay barre
[2024-04-06 15:23:49.169826] [INFO] [main.py] [21] inizio set overlay testo
Error: cannot import name '_imagingft' from 'PIL' (/home/spino/.local/lib/python3.10/site-packages/PIL/init.py)
[2024-04-06 15:23:49.175737] [INFO] [main.py] [23] fine set overlay testo
Tempo di esecuzione: 13.048155307769775 secondi

same error this is running on raspberrry pi2

@radarhere
Copy link
Member

radarhere commented Apr 6, 2024

I've realised I was wrong - you're not installing from source for python3. I suspect you're using piwheels like #5818.

Could you try this?

python3 -m pip uninstall Pillow
python3 -m pip install Pillow --no-binary :all:

@SPIN04
Copy link
Author

SPIN04 commented Apr 7, 2024

same error, i tryed to reinstall the OS and the same error occurred during the installation of pillow WARNING: Generating metadata for package Pillow produced metadata for project name unknown. Fix your #egg=Pillow fragments.
Discarding https://files.pythonhosted.org/packages/f8/3e/32cbd0129a28686621434cbf17bb64bf1458bfb838f1f668262fefce145c/pillow-10.2.0.tar.gz#sha256=e87f0b2c78157e12d7686b27d63c070fd65d994e8ddae6f328e0dcf4a0cd007e (from https://pypi.org/simple/pillow/) (requires-python:>=3.8): Requested unknown from https://files.pythonhosted.org/packages/f8/3e/32cbd0129a28686621434cbf17bb64bf1458bfb838f1f668262fefce145c/pillow-10.2.0.tar.gz#sha256=e87f0b2c78157e12d7686b27d63c070fd65d994e8ddae6f328e0dcf4a0cd007e has inconsistent name: filename has 'pillow', but metadata has 'unknown'
Downloading Pillow-10.1.0.tar.gz (50.8 MB)

the only onw that work is the 10.1.0 but there is always this error Error: cannot import name '_imagingft' from 'PIL' (/home/spino/.local/lib/python3.10/site-packages/PIL/init.py)
now i'm trying to reinstall again everythin

spino@api:~$ sudo apt-get install libfreetype6-dev

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libbrotli-dev libfreetype-dev libpng-dev libpng-tools
Suggested packages:
freetype2-doc
The following NEW packages will be installed:
libbrotli-dev libfreetype-dev libfreetype6-dev libpng-dev libpng-tools
0 upgraded, 5 newly installed, 0 to remove and 57 not upgraded.
Need to get 1029 kB of archives.
After this operation, 3123 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports jammy/main armhf libbrotli-dev armhf 1.0.9-2build6 [320 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports jammy/main armhf libpng-dev armhf 1.6.37-3build5 [176 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main armhf libfreetype-dev armhf 2.11.1+dfsg-1ubuntu0.2 [498 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports jammy-updates/main armhf libfreetype6-dev armhf 2.11.1+dfsg-1ubuntu0.2 [8292 B]
Get:5 http://ports.ubuntu.com/ubuntu-ports jammy/main armhf libpng-tools armhf 1.6.37-3build5 [26.0 kB]
Fetched 1029 kB in 1s (1983 kB/s)
Selecting previously unselected package libbrotli-dev:armhf.
(Reading database ... 76703 files and directories currently installed.)
Preparing to unpack .../libbrotli-dev_1.0.9-2build6_armhf.deb ...
Unpacking libbrotli-dev:armhf (1.0.9-2build6) ...
Selecting previously unselected package libpng-dev:armhf.
Preparing to unpack .../libpng-dev_1.6.37-3build5_armhf.deb ...
Unpacking libpng-dev:armhf (1.6.37-3build5) ...
Selecting previously unselected package libfreetype-dev:armhf.
Preparing to unpack .../libfreetype-dev_2.11.1+dfsg-1ubuntu0.2_armhf.deb ...
Unpacking libfreetype-dev:armhf (2.11.1+dfsg-1ubuntu0.2) ...
Selecting previously unselected package libfreetype6-dev:armhf.
Preparing to unpack .../libfreetype6-dev_2.11.1+dfsg-1ubuntu0.2_armhf.deb ...
Unpacking libfreetype6-dev:armhf (2.11.1+dfsg-1ubuntu0.2) ...
Selecting previously unselected package libpng-tools.
Preparing to unpack .../libpng-tools_1.6.37-3build5_armhf.deb ...
Unpacking libpng-tools (1.6.37-3build5) ...
Setting up libpng-tools (1.6.37-3build5) ...
Setting up libpng-dev:armhf (1.6.37-3build5) ...
Setting up libbrotli-dev:armhf (1.0.9-2build6) ...
Setting up libfreetype-dev:armhf (2.11.1+dfsg-1ubuntu0.2) ...
Setting up libfreetype6-dev:armhf (2.11.1+dfsg-1ubuntu0.2) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

Failed to check for processor microcode upgrades.

Restarting services...
Service restarts being deferred:
/etc/needrestart/restart.d/dbus.service
systemctl restart networkd-dispatcher.service
systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
spino@api:~$ pip install pillow==10.3.0
Defaulting to user installation because normal site-packages is not writeable
Collecting pillow==10.3.0
Downloading pillow-10.3.0.tar.gz (46.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.6/46.6 MB 1.1 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
WARNING: Generating metadata for package pillow produced metadata for project name unknown. Fix your #egg=pillow fragments.
Discarding https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d (from https://pypi.org/simple/pillow/) (requires-python:>=3.8): Requested unknown from https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d has inconsistent name: filename has 'pillow', but metadata has 'unknown'
ERROR: Could not find a version that satisfies the requirement pillow==10.3.0 (from versions: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 2.0.0, 2.1.0, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.4.0, 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0, 2.6.1, 2.6.2, 2.7.0, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 3.0.0, 3.1.0rc1, 3.1.0, 3.1.1, 3.1.2, 3.2.0, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.4.0, 3.4.1, 3.4.2, 4.0.0, 4.1.0, 4.1.1, 4.2.0, 4.2.1, 4.3.0, 5.0.0, 5.1.0, 5.2.0, 5.3.0, 5.4.0, 5.4.1, 6.0.0, 6.1.0, 6.2.0, 6.2.1, 6.2.2, 7.0.0, 7.1.0, 7.1.1, 7.1.2, 7.2.0, 8.0.0, 8.0.1, 8.1.0, 8.1.1, 8.1.2, 8.2.0, 8.3.0, 8.3.1, 8.3.2, 8.4.0, 9.0.0, 9.0.1, 9.1.0, 9.1.1, 9.2.0, 9.3.0, 9.4.0, 9.5.0, 10.0.0, 10.0.1, 10.1.0, 10.2.0, 10.3.0)
ERROR: No matching distribution found for pillow==10.3.0

spino@api:~$ python3 -m pip install Pillow --no-binary :all:
Defaulting to user installation because normal site-packages is not writeable
Collecting Pillow
Using cached pillow-10.3.0.tar.gz (46.6 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
WARNING: Generating metadata for package Pillow produced metadata for project name unknown. Fix your #egg=Pillow fragments.
Discarding https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d (from https://pypi.org/simple/pillow/) (requires-python:>=3.8): Requested unknown from https://files.pythonhosted.org/packages/ef/43/c50c17c5f7d438e836c169e343695534c38c77f60e7c90389bd77981bc21/pillow-10.3.0.tar.gz#sha256=9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d has inconsistent name: filename has 'pillow', but metadata has 'unknown'
Downloading pillow-10.2.0.tar.gz (46.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 46.2/46.2 MB 1.3 MB/s eta 0:00:00
^CERROR: Operation cancelled by user

@radarhere
Copy link
Member

Could you try upgrading pip?

python3 -m pip install --upgrade pip
python3 -m pip uninstall Pillow
python3 -m pip install Pillow --no-binary :all:

Also, why do you keep cancelling the operation?

@SPIN04
Copy link
Author

SPIN04 commented Apr 7, 2024

i have tryed something and instaled a bounch of package, now is working but i have a different error when i run the code
all the file are in the cam folder and has 777 permission

spino@api:~/cam$ python3 main.py
[2024-04-07 14:54:57.371576] [INFO] [main.py] [6] inizio scatto
[2024-04-07 14:54:57.380451] [DEBUG] [main.py] [9] dentro try
[2024-04-07 14:55:10.075407] [DEBUG] [main.py] [12] dopo scatto
[2024-04-07 14:55:10.077701] [INFO] [main.py] [16] fine scatto
[2024-04-07 14:55:10.081333] [INFO] [main.py] [18] inizio set overlay barre
[2024-04-07 14:55:10.430679] [INFO] [main.py] [20] fine set overlay barre
[2024-04-07 14:55:10.434453] [INFO] [main.py] [22] inizio set overlay testo
Error: cannot open resource<-------------------------------------------------------------------------------------
[2024-04-07 14:55:10.447879] [INFO] [main.py] [24] fine set overlay testo
Tempo di esecuzione: 13.152425765991211 secondi

@radarhere
Copy link
Member

I expect that is trying to tell you that the path to the font is incorrect.

@SPIN04
Copy link
Author

SPIN04 commented Apr 7, 2024

fixed, now it is writing, no error but i wonder if there is a way to get the height that the text will cover
getlength but i can't find in the documentation the height

@nulano
Copy link
Contributor

nulano commented Apr 7, 2024

See draw.textbbox

@SPIN04
Copy link
Author

SPIN04 commented Apr 7, 2024

ok now it works fine

@bryankaplan
Copy link

i have tryed something and instaled a bounch of package, now is working

@SPIN04 Could you please be a lot more specific? I am encountering this error, and I'd like to know how to fix it. What do I need to install, specifically?

@aclark4life
Copy link
Member

@bryankaplan Can you import _imagingft? Not that you'd normally do that, but that may tell you if you have a font path issue or something else.


Last login: Wed Jul 31 14:20:45 on ttys000
[oh-my-zsh] Random theme 'josh' loaded

alexclark@alexclarks-Air /Users/alexclark/Developer/zeitbyte/zeitcaster-events                                                                        develop
⚡ cd `tmp`

alexclark@alexclarks-Air /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpu6gq58py                                                                           
⚡ v
Using Python 3.12.4 interpreter at: /opt/homebrew/opt/[email protected]/bin/python3.12
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
Looking in links: /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpqc7gg9xh
Processing /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpqc7gg9xh/pip-24.0-py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-24.0

alexclark@alexclarks-Air /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpu6gq58py                                                                           
⚡ s
(tmpu6gq58py) 
alexclark@alexclarks-Air /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpu6gq58py                                                                           
⚡ pip install Pillow
Collecting Pillow
  Using cached pillow-10.4.0-cp312-cp312-macosx_11_0_arm64.whl.metadata (9.2 kB)
Using cached pillow-10.4.0-cp312-cp312-macosx_11_0_arm64.whl (3.4 MB)
Installing collected packages: Pillow
Successfully installed Pillow-10.4.0

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
(tmpu6gq58py) 
alexclark@alexclarks-Air /var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpu6gq58py                                                                           
⚡ python
Python 3.12.4 (main, Jun  6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import _imagingft
>>> 

@bryankaplan
Copy link

@aclark4life Negative.

In [1]: from PIL import _imagingft
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from PIL import _imagingft

ImportError: cannot import name '_imagingft' from 'PIL' ([REDACTED]/venv/lib/python3.12/site-packages/PIL/__init__.py)

@aclark4life
Copy link
Member

@aclark4life Negative.

OK then, installation issue. For whatever it's worth, my macOS wheel appears to be dynamically linked to Homebrew deps

(tmpl1upjlzp) ➜  tmpl1upjlzp  otool -L /private/var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpl1upjlzp/.venv/lib/python3.12/site-packages/PIL/_imagingft.cpython-312-darwin.so
/private/var/folders/mm/j6wyq9tx3_q669dsp5kfsj_80000gn/T/tmpl1upjlzp/.venv/lib/python3.12/site-packages/PIL/_imagingft.cpython-312-darwin.so:
	@loader_path/.dylibs/libfreetype.6.dylib (compatibility version 27.0.0, current version 27.1.0)
	@loader_path/.dylibs/libharfbuzz.0.dylib (compatibility version 60851.0.0, current version 60851.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
(tmpl1upjlzp) ➜  tmpl1upjlzp  brew search freetype
==> Formulae
freetype ✔                                                                       freebayes

==> Casks
freetube
(tmpl1upjlzp) ➜  tmpl1upjlzp  brew search harfbuzz   
==> Formulae
harfbuzz ✔                                                                       harbour
(tmpl1upjlzp) ➜  tmpl1upjlzp  

@bryankaplan
Copy link

Agreed, it's an installation issue, and I'm probably missing some dependency. I'm on Void Linux. I already had both harfbuzz-devel and freetype-devel installed.

@nulano
Copy link
Contributor

nulano commented Jul 31, 2024

i have tryed something and instaled a bounch of package, now is working

@SPIN04 Could you please be a lot more specific? I am encountering this error, and I'd like to know how to fix it. What do I need to install, specifically?

In most cases you don't need to install anything other than just Pillow, and I usually find that the exceptions are easiest to diagnose starting from the beginning. So could you please create a new issue, making sure to provide your OS version and output from running python3 -m PIL.report as shown in the template, as well as how you installed Pillow?

@bryankaplan
Copy link

@nulano Thank you. Done ^.

@aclark4life
Copy link
Member

In most cases you don't need to install anything other than just Pillow

Right, I had to go look it up. I forgot the most important difference between static and dynamic linking is linking-at-compile-time vs. linking-at-runtime. So in my example, if I were to unzip the Pillow wheel, I'd find the dylibs whose path begins with @loader_path. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Installation Usually a problem with … Linux
Projects
None yet
Development

No branches or pull requests

5 participants