• DepthAI
  • any luck running depthai in WSL2 yet?

I am trying to run depthai in WSL2.

I have gotten maddening close...RuntimeError: Failed to find device after booting, error message: X_LINK_DEVICE_NOT_FOUND

Every time it fails, it removes the device from WSL and I have to reattach it.

Set udev rules

(depthai_p3venv) mike@MSI:~/oak/depthai/depthai$ echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="03e7", MODE="0666"' | sudo tee /etc/udev/rules.d/80-movidius.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="03e7", MODE="0666"

(depthai_p3venv) mike@MSI:~/oak/depthai/depthai$ sudo udevadm control --reload-rules && sudo udevadm trigger

PLUG IN CAMERA AT THIS POINT

Attach USB device to WSL Distro

IN POWERSHELL: usbipd wsl attach --busid 1-4

Verify USB device is present in Linux

(depthai_p3venv) mike@MSI:~/oak/depthai/depthai$ lsusb | grep 03e7
Bus 001 Device 014: ID 03e7:2485 Intel Movidius MyriadX

Start DepthAI (tried using usb3 and usb2)

(depthai_p3venv) mike@MSI:~/oak/depthai/depthai$ python depthai_demo.py -usbs usb2

Fails to find device after rebooting:

Using depthai module from:  /home/mike/oak/depthai/python/depthai_p3venv/lib/python3.8/site-packages/depthai.cpython-38-x86_64-linux-gnu.so
Depthai version installed:  2.15.4.0
Setting up demo...
Available devices:
[0] 19443010E163EF1200 [X_LINK_UNBOOTED]
  File "depthai_demo.py", line 677, in run
    self.instance.run_all(self.conf)
  File "depthai_demo.py", line 128, in run_all
    self.setup(conf)
  File "depthai_demo.py", line 211, in setup
    self._device = dai.Device(self._pm.pipeline.getOpenVINOVersion(), self._deviceInfo, usb2Mode=self._conf.args.usbSpeed == "usb2")
RuntimeError: Failed to find device after booting, error message: X_LINK_DEVICE_NOT_FOUND

Results of dmesg -w:

[ 2876.534317] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[ 2876.534319] vhci_hcd vhci_hcd.0: devid(65540) speed(3) speed_str(high-speed)
[ 2876.534345] vhci_hcd vhci_hcd.0: Device attached
[ 2876.882470] usb 1-1: new high-speed USB device number 12 using vhci_hcd
[ 2877.032357] usb 1-1: SetAddress Request (12) to port 0
[ 2877.064829] usb 1-1: New USB device found, idVendor=03e7, idProduct=2485, bcdDevice= 0.01
[ 2877.064831] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2877.064832] usb 1-1: Product: Movidius MyriadX
[ 2877.064833] usb 1-1: Manufacturer: Movidius Ltd.
[ 2877.064833] usb 1-1: SerialNumber: 03e72485
[ 2906.790263] vhci_hcd: connection closed
[ 2906.790419] vhci_hcd: stop threads
[ 2906.790421] vhci_hcd: release socket
[ 2906.790425] vhci_hcd: disconnect device
[ 2906.790446] usb 1-1: USB disconnect, device number 12
  • erik replied to this.

    Hi SpudTheBot , few people have tried it but I don't think anyone had much success. Usb passthrough isn't that simple to implement, IIRC there was some mention of recompiling the kernel (no idea if that's needed or not). So I would just avoid using it.
    Thanks, Erik

    I GOT depthai DEMO TO RUN IN WSL!!!!!!!

    The clue came from reading about the trickery required to run it in VirtualBox...the camera disappears and re-appears as a different device after it is rebooted by the program...

    I opened a PowerShell window as admin and another PowerShell as admin and started WSL in the second window (may not require admin for the WSL window, but MUST be admin for the PowerShell window to attach the USB device or you will get an error).

    Both windows must be left open.

    Before starting the demo (and causing camera reboot), the camera showed up with ID 2-4 using usbipd wsl list , so before running the depthai demo in PowerShell, I attached the device to Ubuntu:

    **usbipd wsl attach --busid 2-4**

    I started the demo in the WSL window and then switched quickly to the PowerShell (without WSL) and used usbipd wsl list repeatedly...after the camera rebooted it changed to:

    2-20   03e7:f63b  Luxonis Device

    So immediately after starting the demo program, I quickly switched to the non WSL PowerShell and repeatedly executed:

    **usbipd wsl attach --busid 2-20**

    This failed several times while the camera was rebooting, and then succeeded when the camera reappeared as a different device.

    Note that the BUSID numbers 2-4 and 2-20 will change from time to time, but seem to be consistent during any single PowerShell / WSL session.

    This requires a bit of fast switching between windows. I already had usbipd wsl attach --busid 2-20 typed into the PowerShell window and ready to execute repeatedly.

    Now to write a batch script that somehow automates this entire process in the PowerShell side...

    2 years later

    Any luck on this yet ? I have tried to do this and it never changed my device name and get stuck in the same loop. Also any idea why the camera power cycle/ resets the connection after getting connected ?

      5 days later

      dinnu66
      I'll see if I can devise a script that will do that. The issue is it has to run on both the host as well as the WSL, so that is a bit of a problem if you don't want to run two separate scripts.

      Thanks,
      Jaka

      dinnu66
      Run this script at all times as powershell admin:

      # Ensure the script is running with administrator privileges
      if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
      {   
          Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
          Break
      }
      
      $vendorId = "03e7"
      $unbootedPid = "2485"
      $bootedPid = "f63b"
      
      function Bind-And-Attach-Device {
          param(
              [string]$busid,
              [string]$vidpid
          )
          Write-Host "Binding device at $busid..."
          & usbipd bind --busid $busid
          if ($LASTEXITCODE -eq 0) {
              Write-Host "Successfully bound device. Now attaching $vidpid to WSL..."
              & usbipd attach --wsl -i $vidpid
              if ($LASTEXITCODE -eq 0) {
                  Write-Host "Successfully attached $vidpid to WSL."
              } else {
                  Write-Host "Failed to attach $vidpid to WSL."
              }
          } else {
              Write-Host "Failed to bind device at $busid."
          }
      }
      
      while ($true) {
          $devices = & usbipd list
      
          # Check for unbooted device
          $unbootedDevice = $devices | Where-Object { $_ -match "$vendorId`:$unbootedPid" }
          if ($unbootedDevice) {
              $busid = ($unbootedDevice -split '\s+')[0]
              $vidpid = ($unbootedDevice -split '\s+')[1]
              Bind-And-Attach-Device -busid $busid -vidpid $vidpid
          }
      
          # Check for booted device
          $bootedDevice = $devices | Where-Object { $_ -match "$vendorId`:$bootedPid" }
          if ($bootedDevice) {
              $busid = ($bootedDevice -split '\s+')[0]
              $vidpid = ($bootedDevice -split '\s+')[1]
              Bind-And-Attach-Device -busid $busid -vidpid $vidpid
          }
      
          Start-Sleep -Seconds 2
      }

      It binds and attaches the luxonis device to WSL. I did not bother implementing multiple device support though.

      Thanks,
      Jaka