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 <noreply@anthropic.com>
This commit is contained in:
parent
74a850a00c
commit
4e44406e71
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user