Dependence on Python 2.7

Basic Information:

Printer Model: Ender 3, heavily modified
MCU / Printerboard: BTT SKR Mini E3 V3
Host / SBC Raspberry Pi 4B, 4 GB memory
klippy.log - none to attach

Describe your issue:

I am attempting to create a new image using Octopi 1.1.0 (Bookworm, Python 3.11) due to the upcoming dropping of support for Python 3.7. I installed Klipper using KIAUH with the Python 3 option. When I run install-octopi.sh the process installs Python 2.7 and makes it the default Python version. Is there any way to avoid installing Python 2.7?

Sure. Don’t run install-octopi.sh.

1 Like

Thanks for the reply, but it is not helpful. The KIAUH installation did not create the files necessary to start the Klipper service. I know from experience that running ~/klipper/scripts/install-octopi.sh does install the files needed to automatically start the Klipper service when I boot the system, but at the cost of installing Python 2.7. I am trying to avoid that, but I do not know how much of the install command file is needed, nor do I know which sections of the file cause loading of Python 2.7.

Can I ask, why are you asking about the Octopi installer script here and not on the Octopi forum?

I don’t think people here have the background to be able to help with your issues.

1 Like

Sure, you can ask. :wink: The reason I am asking here is that this is a Klipper issue. I have no clue what dependencies Klipper has on Python 2.7. I doubt that anyone in the OctoPrint forum has as much knowledge about the Klipper install-octopi.sh script as I would hope somebody on this forum would.

My issue is that I have the Klipper software installed, and apparently working (at least that is what KIAUH said), however, it does not automatically start as I would expect. The file that creates the Klipper daemon is ~/klipper/scripts/install-octopi.sh. It also installs Python 2.7. Perhaps I was not explicit enough when I asked my original question. Let me try to be more clear.

  1. What, if any, dependencies does the Python 3 version of Klipper have on Python 2.7?
  2. Is there a way to work around the Python 2.7 dependencies?
  3. Can I just create the Klipper service definition file and use systemctl to enable it as a system service?
  4. If this is possible, how do I go about it?
  5. Can I edit ~/klipper/scripts/install-octopi.local to accomplish what I would like, without the need to install Python 2.7?

I hope this helps to better explain what I am looking for. For what it’s worth, there is a klippy-env directory in my home directory. I did not write the install-octopi.sh script, so I do not undersand the full intent of the script and do not know what I can get rid of and still have the Klipper installation work.

When you use OctoPi, what is the use of install-octopi.sh?

My workflow for this is:

  1. Install Rasperry Pi OS from Rasperry Pi Imager according the Pi that is used
  2. Install and run KIAUH
  3. Install OctoPrint with GitHub - paukstelis/octoprint_deploy: Bash script for rapid deployment of multiple octoprint instance on a single machine
  • With mixed installations, there is no hproxxy for Octoprint. You have to access via http://[ip-address]:5000
  • The serial access point from OctoPrint to Klipper is /home/pi/printer_data/comms/klippy.serial

OctoPrint does not run on the OS-installed Python. it runs on it’s own Python in a virtual environment (venv) which comes with the installation of OctoPrint.

1 Like

If you look at the script:

It installs Klipper on an rPi which has Octopi running on it - if you read through it, you’ll see that the script itself uses resources that Octopi loaded in for its use (ie Python 2.7).

@pigaro

If you look at the Klipper master scripts repository:

You’ll see that the last time there was updates made to install-octopi.sh was four years ago (by Kevin). Since then (actually just less than four years ago) Klipper migration to Python 3.* started: Upcoming v0.10.0 Release

Based on these dates and the fact that you seem to be the first person who has issue with install-octopi.sh that I can find, I don’t think it’s a viable method for installing Klipper with Octopi.

As I am writing this post, I see that @EddyMI3D has provided you with a basic installation and connection workflow for using Octopi with Klipper.

This will undoubtedly be the most expedient way for you to get the two software packages working together.

2 Likes

Thanks for the clarification.

Thanks for the information. The posting at the link you provided (about v0.10.0 release) was helpful and implies (at least to me) that Klipper does not require Python 2.7. Looking at the install-octopi.sh file I noted an explicit reference to python2 in Step 2 (creating a python virtual environment). Looking at a more recent installer script (install-ubuntu-22.04.sh) I noted that this script explicitly references python3 where the octopi script referenced python or python2. I will try changing the Python package list definitions in the octopi script to python3 and see if that does what I want.

Thanks for the information. The workflow I am using is:

  1. Use the Raspberry Pi Imager to install Octopi 1.1.0 which includes Raspbian Bookworm, Python 3.11, and OctoPrint 1.11.0. This image allows OctoPrint to be accessed from port 80.
  2. Install and run KIAUH
  3. Install Klipper with KIAUH
  4. Install the Klipper startup using ~/klipper/scripts/install-octopi.sh

This seems to work, but as I noted step 4 causes Python 2.7 to be installed. I plan to try a modified script (see above) that specifies Python 3.

This is not needed and in doubt just causes chaos. All relevant installation steps are done by KIAUH.
IIRC, that newer KIAUH versions (>v4?) can even completely take over the installation of Klipper and Octoprint on a bare metal Linux system.

When I reboot after the KIAUH Klipper install there is no evidence that Klipper is running. When I looked in /etc/init.d and /etc/default there was no entry for Klipper.

If you are amenable, I would suggest that I create a new thread for this discussion.

I modified the install-octopi.sh script to change the Python references in Step 1 to be python3-dev instead of python-dev (probably does not matter) and in Step 2 from virtualenv -p python2 to virtualenv -p python3. The script apparently did what I was looking for (see below).
Thanks to all who helped.

Now, is there a way to update the install-octopi.sh script in the official repository to either explicitly specify python3 or to change the python2 in Step 2 to python?

--------------------- results from running modified script -----------------------------------

pi@octopi:~/klipper/scripts $ ./install-octopi.sh

Running apt-get update…

[sudo] password for pi:
Get:1 Index of /debian bookworm InRelease [54.8 kB]
Get:2 Index of /raspbian bookworm InRelease [15.0 kB]
Get:3 Index of /raspbian bookworm/main armhf Packages [14.5 MB]
Get:4 Index of /debian bookworm/main armhf Packages [539 kB]
Get:5 Index of /debian bookworm/main arm64 Packages [537 kB]
Fetched 15.6 MB in 17s (906 kB/s)
Reading package lists… Done
W: http://raspbian.raspberrypi.com/raspbian/dists/bookworm/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.

Installing packages…

Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Note, selecting ā€˜libusb-1.0-0-dev’ for regex ā€˜libusb-1.0’
Note, selecting ā€˜libusb-1.0-doc’ for regex ā€˜libusb-1.0’
Note, selecting ā€˜libusb-1.0-0’ for regex ā€˜libusb-1.0’
virtualenv is already the newest version (20.17.1+ds-1).
python3-dev is already the newest version (3.11.2-1).
libffi-dev is already the newest version (3.4.4-1).
build-essential is already the newest version (12.9).
libncurses-dev is already the newest version (6.4-4).
libusb-dev is already the newest version (2:0.1.12-32).
avrdude is already the newest version (7.1+dfsg-3).
gcc-avr is already the newest version (1:5.4.0+Atmel3.6.2-3).
binutils-avr is already the newest version (2.26.20160125+Atmel3.6.2-4).
avr-libc is already the newest version (1:2.0.0+Atmel3.6.2-3).
stm32flash is already the newest version (0.7-1).
dfu-util is already the newest version (0.11-1+b5).
libnewlib-arm-none-eabi is already the newest version (3.3.0-1.3+deb12u1).
gcc-arm-none-eabi is already the newest version (15:12.2.rel1-1).
binutils-arm-none-eabi is already the newest version (2.39-8+rpi1+18).
libusb-1.0-0 is already the newest version (2:1.0.26-1).
libusb-1.0-0-dev is already the newest version (2:1.0.26-1).
libusb-1.0-doc is already the newest version (2:1.0.26-1).
0 upgraded, 0 newly installed, 0 to remove and 115 not upgraded.

Updating python virtual environment…

Looking in indexes: Simple index, piwheels - Simple index
Ignoring greenlet: markers ā€˜python_version >= ā€œ3.12ā€ā€™ don’t match your environment
Ignoring setuptools: markers ā€˜python_version >= ā€œ3.12ā€ā€™ don’t match your environment
Requirement already satisfied: cffi==1.14.6 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 7)) (1.14.6)
Requirement already satisfied: greenlet==2.0.2 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 9)) (2.0.2)
Requirement already satisfied: Jinja2==2.11.3 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 12)) (2.11.3)
Requirement already satisfied: markupsafe==1.1.1 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 13)) (1.1.1)
Requirement already satisfied: pyserial==3.4 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 15)) (3.4)
Requirement already satisfied: python-can==3.3.4 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 17)) (3.3.4)
Requirement already satisfied: msgspec==0.19.0 in /home/pi/klippy-env/lib/python3.11/site-packages (from -r /home/pi/klipper/scripts/klippy-requirements.txt (line 20)) (0.19.0)
Requirement already satisfied: pycparser in /home/pi/klippy-env/lib/python3.11/site-packages (from cffi==1.14.6->-r /home/pi/klipper/scripts/klippy-requirements.txt (line 7)) (2.22)
Requirement already satisfied: aenum in /home/pi/klippy-env/lib/python3.11/site-packages (from python-can==3.3.4->-r /home/pi/klipper/scripts/klippy-requirements.txt (line 17)) (3.1.16)
Requirement already satisfied: wrapt~=1.10 in /home/pi/klippy-env/lib/python3.11/site-packages (from python-can==3.3.4->-r /home/pi/klipper/scripts/klippy-requirements.txt (line 17)) (1.17.2)

Installing system start script…
Installing system start configuration…
Launching Klipper host software…

Restarting klipper (via systemctl): klipper.service.

Not sure what is happening on your end, but Klipper does not use init.d anymore; it uses systemd service management instead. Typically, all halfway modern Linux distributions should support it.

To properly check if Klipper is correctly installed as a service, you can use the following command:

systemctl status klipper

Or, to check if there have been any startup errors, you can use:

sudo journalctl -u klipper

Edit:
As a sidenote:

  • The install script also uses systemd and not init.d.
  • There are considerations to deprecate the installation scripts altogether, as they are essentially no longer maintained due to KIAUH.

I am planning to retry the KIAUH install on an Octopi 1.1.0 image to better understand what is happening. I will open a new thread specifically on this topic if the new attempt behaves like my previous attempts.

1 Like

I did that before on OctoPi 1.0.0 and ended up to reinstall OctoPrint with octoprint_deploy