From 4e44406e713cd22ea37299b5c7977d9d3d1119d4 Mon Sep 17 00:00:00 2001 From: jim800121chen Date: Mon, 9 Mar 2026 20:48:09 +0800 Subject: [PATCH] fix: resolve "no backend available" libusb error on Windows kneron_detect.py now prepends the install directory to PATH before importing pyusb, so libusb-1.0.dll in the install dir is found. DetectHardware() also sets PATH in the subprocess environment. Co-Authored-By: Claude Opus 4.6 --- edge-ai-platform/installer/app.go | 6 ++++++ edge-ai-platform/scripts/kneron_detect.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/edge-ai-platform/installer/app.go b/edge-ai-platform/installer/app.go index e665519..4ad9c8f 100644 --- a/edge-ai-platform/installer/app.go +++ b/edge-ai-platform/installer/app.go @@ -559,6 +559,12 @@ func (inst *Installer) DetectHardware() ([]HardwareDevice, error) { } cmd := exec.Command(pythonPath, detectScript) + cmd.Dir = installDir + // Ensure libusb-1.0.dll can be found on Windows by adding install dir to PATH + cmd.Env = append(os.Environ(), fmt.Sprintf("PATH=%s;%s;%s", + installDir, + filepath.Join(installDir, "scripts"), + os.Getenv("PATH"))) out, err := cmd.CombinedOutput() if err != nil { return nil, fmt.Errorf("detection failed: %s — %w", string(out), err) diff --git a/edge-ai-platform/scripts/kneron_detect.py b/edge-ai-platform/scripts/kneron_detect.py index 95b338b..7bf4d40 100644 --- a/edge-ai-platform/scripts/kneron_detect.py +++ b/edge-ai-platform/scripts/kneron_detect.py @@ -1,6 +1,18 @@ """Kneron USB device detection — shared by install scripts and kneron_bridge.py""" +import os import sys +# On Windows, ensure libusb-1.0.dll can be found by pyusb. +# The DLL may be in the install directory or scripts/ subdirectory. +if sys.platform == "win32": + _script_dir = os.path.dirname(os.path.abspath(__file__)) + _install_dir = os.path.dirname(_script_dir) + for _dir in [_install_dir, _script_dir]: + _dll = os.path.join(_dir, "libusb-1.0.dll") + if os.path.isfile(_dll): + os.environ["PATH"] = _dir + ";" + os.environ.get("PATH", "") + break + try: import usb.core except ImportError: