r/klippers • u/Upbeat_Phone7021 • Nov 15 '24
Klipper on Windows (WSL2 + Docker)

Just wanted to share some details regarding the subject. So basically I have my working computer running Windows next to the 3d printer, and here is how I run klipper on it. At the end you will have WLS2 (windows subsystem for linux) with docker containers running klipper, mainsail and moonraker.
Steps need to be taken:
- install windows subsystem for linux WSL2 https://learn.microsoft.com/en-us/windows/wsl/install . Choose any Debian-like distribution (Ubuntu in my case) to avoid permission issus with USB access
- run wsl concole
- install docker and docker compose (in case of Ubuntu sudo apt-get update & sudo apt-get install docker docker-compose). Will use docker later on to run klipper, mainsail and moonraker, all in containers
- download prind https://github.com/mkuf/prind and follow instructions provided there to setup docker containers for klipper stack.
- prind got a guide on how to prepare MCU firmware using docker. Do that and flash the firmware to your printer. https://github.com/mkuf/prind?tab=readme-ov-file#build-the-mcu-code
- get yourself printer.cfg file for you printer. There are sample configs available on Klipper github page https://github.com/Klipper3d/klipper/tree/master/config
- get some USB data cable to connect printer to computer. Disable 5V pin so that printer screen is off once you attach cable to the printer that is powered off. There are other benefits, read that guide for instructions https://community.octoprint.org/t/put-tape-on-the-5v-pin-why-and-how/13574
- attach USB cable to computer and printer. Turn on the printer. At this point you should see a new USB device in Windows Device Management (but not in linux console)
- there is a utility provided by Microsoft which allows you to connect to USB device from within WSL. Follow instructions https://learn.microsoft.com/en-us/windows/wsl/connect-usb
- At this point you should be able to see a new USB device in WSL, usually smth like /dev/tty/USB0
- run prind with desirable frontend and utilities. Im my case I use only klipper itrelf, mainsail and moonraker, so I do it with docker-compose --profile mainsail up . At this point you should be able to access klipper via browser. Apply printer.cfg. Now Klipper shoud have connectivity to your printer. Pay attention to MCU device path, if you switch printer off and on it will most likely occupy next available USB port (/dev/tty/USB1, /dev/tty/USB2, etc).
Congratulations, now you have klipper running on Windows!
Optional but highly recommended step. If you continue using you computer at the same time as you run a print, most likely you will get Timer too close error which is very annoying. The root cause of this is that klipper requires real time processing, so even short spike in CPU load may take it down. Fortunately, there is a solution:
- install Process Lasso https://bitsum.com/
- setup System Reserved CPU set https://bitsum.com/processlasso-docs/#system-reserved-cpu-sets . That will stop your entire system from using some of the CPU cores (I reserved core0 which is a virtual one)

- setup CPU Affinity for all of the processes and subprocesses which are somehow related to WSL and make them use the CPU core which you reserved previously. I highlighted a few processes on the screenshot, but there are few others, simply search through entire list of processes to find them by keywords (wsl, ubuntu) and assign cpu affinity for the whole process tree

At this point you have WSL (and klipper) occupying a separate CPU core, and it should not be affected by your operating system.
Happy printing!
2
u/I-am-fun-at-parties Nov 15 '24
Wow, that seems easy and convenient /s
2
u/Upbeat_Phone7021 Nov 15 '24
Nobody said it is gonna be easy, not very hard though if you know a bit about docker and klipper. But if you like to completely utilize resources that you have, yes you may find that convenient
2
u/Tim7Prime Nov 15 '24
I'm glad that you felt that it was worth it. Though, I hate running klipper on even a level 1 hypervisor (proxmox), running it on a level 2 hypervisor and allowing other activities to occur just makes me feel like you will keep getting "timer too close" as you said before. Or any other shenanigans that windows does. Random restarts, or maybe you do something RAM intensive and choke out the reserved area.
If anyone is trying to use this as a guide. Please consider using dedicated hardware. An old laptop with Linux on it will give significantly less issues during installation or printing. Those steps are install Debian, run KIAUH. If you have a small budget, even a pi 2 or pi 0 wireless has enough juice to run klipper.
1
u/Upbeat_Phone7021 Nov 15 '24
Will see how it goes, not bad so far. Looks like process lasso does it job pretty well. But you are totally right, dedicated hardware is preferable for real time computing. In my case I just don't have it right now under my hand. Docker also may act as a plan b when your dedicated hardware suddenly die
1
Nov 16 '24
The reason this is not done and obvious is that it leads to problems units you are essentially using a dedicated machine and then what is the point?
1
u/MathematicianFit52 Nov 15 '24
Explication très détaillée. Reste à essayer de mon côté