Cpython bug?! include path break after rgbmatrix()

Hi,
I compiled the python bindings from the github repo
GitHub - hzeller/rpi-rgb-led-matrix: Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO

it compiles and i can use it.
i made a VENV that i use for all those libs.

somehow there is some weird fuckup with the cpython doing strange things to the include path?
i am not sure where to post this. maybe github issues?

THIS works:
from PIL import Image
image.open(“/tmp/foo.png”)

THIS fails:
import rgbmatrix
options = rgbmatrix.RGBMatrixOptions()
options.rows = 64
options.cols = 64
options.chain_length = 2
options.parallel = 2
options.brightness = 10
options.hardware_mapping = ‘regular’

rgbmatrix.RGBMatrix(options = options)
<rgbmatrix.core.RGBMatrix object at 0x7f88c32f50>

from PIL import Image
Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘PIL’

i made logs with python -v -v

the working one looks like this:

/home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL/pycache/init.cpython-311.pyc matches /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL/init.py
code object from ‘/home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL/pycache/init.cpython-311.pyc’

the failed one looks like this:
trying /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL.cpython-311-aarch64-linux-gnu.so trying /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL.abi3.so
trying /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL.so
trying /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL.py
trying /home/pewpew/blinkenschild/venv/lib/python3.11/site-packages/PIL.pyc
Traceback (most recent call last):
File “”, line 1, in
File “”, line 1178, in _find_and_load
File “”, line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named ‘PIL’

anyone got any ideas what to do?!

apparently this happens only when i run python in the venv as root?!

SOLUTION / WORKAROUND

this is a weird bug that has to do with VENV and opython and not with this library.
i managed to use a hack to get it running.
the hack involves setting everything up in VENV but not using it later to run it.
instead i use

import sys
sys.path.append(“venv/lib/python3.11/site-packages/”)

and run the script with the python interpreter and paths from the host system.

i THINK the bug happens because rgbmatrix is built and installed systemwide depending on PIL and the venv uses another version of PIL at some point?