Some context, I am using a raspberry pi 5
running pi-os bookworm 12
. I have a coral ai usb
accelerator, and I am trying to run a tflite
model on it. Due to pycoral
only supporting versions 3.6 to 3.9
, I installed 3.9.0
using pyenv
. However, I had to build it without some packages due to not being able to install them no matter what I searched. I then tried to run a test script
#!/usr/bin/env python3
from pathlib import Path
from tflite_runtime.interpreter import Interpreter, load_delegate
MODEL = Path("/home/USER/models/efficientdet_lite1_int8_edgetpu.tflite")
delg = load_delegate("/usr/lib/aarch64-linux-gnu/libedgetpu.so.1")
interp = Interpreter(model_path=str(MODEL), experimental_delegates=[delg])
interp.allocate_tensors()
print("? allocate_tensors() OK ? interpreter built successfully")
But I got the error:
Traceback (most recent call last):
File "/home/USER/test_tpu_model.py", line 3, in <module>
from tflite_runtime.interpreter import Interpreter, load_delegate
File "/home/USER/tflite-env-2/lib/python3.9/site-packages/tflite_runtime/interpreter.py", line 21, in <module>
import ctypes
File "/home/USER/.pyenv/versions/3.9.18/lib/python3.9/ctypes/init.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
I did some research and found that it was due to not having the module libffi-dev
when compiling 3.9.0, but no matter what I do, I can not find a way to install libff-dev
I have updated my source list multiple times
My sources.list:
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
deb http://archive.raspberrypi.org/debian/ bookworm main
My coral-edgetpu.list:
deb https://packages.cloud.google.com/apt coral-edgetpu-stable main
My raspi.list:
deb http://archive.raspberrypi.com/debian/ bookworm main contrib non-free rp
#deb-src http://archive.raspberrypi.com/debian/ bookworm main
Noting pops up when I apt-cache search
for it
USER@raspberrypi:\~ $ apt-cache search libffi | grep dev
USER@raspberrypi:\~ $
Same thing happens with apt-cache search "libffi.*dev"
When I try to just sudo apt-get install
it I get the error:
USER@raspberrypi:~ $ sudo apt-get install libffi-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package libffi-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libffi-dev' has no installation candidate
This usually means libffi-dev wasn’t installed when building Python. On Pi OS Bookworm 64-bit, it can be tricky since libffi-dev sometimes doesn’t show up in apt.
You can manually download the .deb from the debian site
Then reinstall Python via pyenv with:
CFLAGS="-I/usr/local/include" \ LDFLAGS="-L/usr/local/lib" \ PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" \ pyenv install 3.9.18
That should fix the missing _ctypes module.