Setting up Klipper – Let’s play

Like OctoPrint, klipper will run in it’s own dedicated virtual environment. We will setup a user for it to run as (klipper) and grant that the limited rights that it needs to run.

Setup user account

sudo useradd -G tty,dialout -m -d /opt/klipper klipper

Option 1) Using the automated scripts…

Setup Klipper by the automated scripts and install with Python2

Allow sudo access from klipper account

As a temporary measure (and only for the installation) we will add this user to sudo and set a password

sudo usermod -a -G sudo klipper
sudo passwd klipper

Install Klippy sources

Switch to the klipper account and pull the git repository:

sudo su klipper -
cd ~
git clone https://github.com/KevinOConnor/klipper

install klippy with the built in script

~/klipper/scripts/install-octopi.sh

Lock down klipper account

sudo passwd -l klipper
sudo deluser klipper sudo

Option 2) Manually…

Manually install klipper with python3 (or 2)…

Install pre-requisites

sudo apt-get install virtualenv python-dev libffi-dev build-essential libncurses-dev libusb-dev avrdude gcc-avr binutils-avr avr-libc stm32flash libnewlib-arm-none-eabi gcc-arm-none-eabi binutils-arm-none-eabi libusb-1.0

Setup Virtual environment

python3 -m venv klippy-venv
source klippy-venv/bin/activate
pip install pip --upgrade

Install klippy requirements

Install klipper pre-requisites

pip install -r klipper/scripts/klippy-requirements.txt
deactivate
exit

After installing, deactivate the virtual environment and drop out of the “klipper” user session

Install startup script

sudo cp "/opt/klipper/scripts/klipper-start.sh" /etc/init.d/klipper
sudo update-rc.d klipper defaults

Install defaults

Create klipper defaults file:

vi /etc/default/klipper

# Configuration for /etc/init.d/klipper

KLIPPY_USER=klipper
KLIPPY_EXEC=/opt/klipper/klippy-venv/bin/python
KLIPPY_ARGS="/opt/klipper/klipper/klippy/klippy.py /opt/klipper/printer.cfg -l /tmp/klippy.log"

Startup Klipper

sudo service klipper start

Octoprint access

When you use the OctoKlipper plugin, you gain access to a tool to load and edit the Klipper config within OctoPrint. To allow this to work, you will need to add the “klipper” group (created automatically for the klipper user earler) to the octoprint user:

sudo usermod -a -G klipper octoprint

You can then specify the location for the config file: /opt/klipper/cfg

If you want OctoPrint to be able to start/stop Klipper, then you will need to add the following line to the sudoer’s file for OctoPrint:

octoprint ALL=NOPASSWD: /usr/sbin/service klipper restart

Gotcha’s

At the time of writing, using the above conf, you may encounter a permissions error accessing the serial port “file” device for Klipper at /tmp/printer. If this occurs, you can modify the startup script so that Klipper instead creates the socket device at /opt/klipper/printer.ser:

KLIPPY_ARGS="/opt/klipper/klipper/klippy/klippy.py 

Comments

Leave a Reply