cx_Freeze + Phidget22 on Linux: libphidget22.so not found

Supporting 2.7 and 3.2+
Welson
Fresh meat
Posts: 3
Joined: Fri Oct 03, 2025 3:49 am

cx_Freeze + Phidget22 on Linux: libphidget22.so not found

Post by Welson »

Hey,

I’m working on a control tool that uses Phidget22 to handle some hardware. Everything runs fine when I launch it with Python (Ubuntu 22.04, Python 3.10), but once I freeze it with cx_Freeze, the binary crashes at startup with:

Code: Select all

Failed to load dynlib/dll 'libphidget22.so'
The library is installed via apt and works perfectly when running the script directly. The issue only happens with the frozen build.

Here’s the setup.py I’m using:

Code: Select all

from cx_Freeze import setup, Executable

build_exe_options = {
"packages": ["Phidget22", "asyncio", "logging", "requests", "json"],
"include_files": [
("/usr/lib/libphidget22.so", "libphidget22.so"),
("config.json", "config.json"),
],
}

setup(
name="control_center",
version="1.4.2",
description="Hardware monitoring tool using Phidget22",
author="Engineering Team",
options={"build_exe": build_exe_options},
executables=[Executable("main.py", target_name="control_center")],
)
Even when launching with LD_LIBRARY_PATH=. or directly from the build folder, the library still isn’t found.
Everything else works fine, except for the part that communicates with the Phidget devices.

Has anyone run into this with cx_Freeze on Linux?
User avatar
Patrick
Lead Developer
Posts: 692
Joined: Mon Jun 20, 2005 8:46 am
Location: Calgary

Re: cx_Freeze + Phidget22 on Linux: libphidget22.so not found

Post by Patrick »

The python library (from PyPI) includes the native library - it expects to find it in a .libs folder. If not, it should find it installed on the system. I'm not familiar with cx_Freeze, but I expect it should work.

Code: Select all

libs_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".libs")
if os.path.exists(os.path.join(libs_path, "libphidget22.so")):
	PhidgetSupport.__dll = cdll.LoadLibrary(os.path.join(libs_path, "libphidget22.so"))
else:
	PhidgetSupport.__dll = cdll.LoadLibrary("libphidget22.so.0")
-Patrick