Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

octoklipper error: externally-managed-environment #493

Open
zaid-hm opened this issue Jul 6, 2024 · 15 comments · May be fixed by #502
Open

octoklipper error: externally-managed-environment #493

zaid-hm opened this issue Jul 6, 2024 · 15 comments · May be fixed by #502

Comments

@zaid-hm
Copy link

zaid-hm commented Jul 6, 2024

I'm trying to run klipper on a galaxy tab A (2019)
But when running the command in the instruction I get the following error:


bash -c "$(curl -fsSL https://raw.githubusercontent.com/feelfreelinux/octo4a/master/scrip
ts/setup-klipper.sh)"
Setting up klipper
Do you have "Plugin extras" installed? (y/n): y
Installing dependencies...

OK: 404 MiB in 183 packages
error: externally-managed-environment

× This environment is externally managed
╰─>
    The system-wide python installation should be maintained using the system
    package manager (apk) only.

    If the package in question is not packaged already (and hence installable via
    "apk add py3-somepackage"), please consider installing it inside a virtual
    environment, e.g.:

    python3 -m venv /path/to/venv
    . /path/to/venv/bin/activate
    pip install mypackage

    To exit the virtual environment, run:

    deactivate

    The virtual environment is not deleted, and can be re-entered by re-sourcing
    the activate file.

    To automatically manage virtual environments, consider using pipx (from the
    pipx package).

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
localhost:~# bash -c "$(curl -fsSL https://raw.githubusercontent.com/feelfreelinux/octo4a/master/scrip
ts/setup-klipper.sh)"
@Bartouzz
Copy link

Bartouzz commented Jul 8, 2024

There is a new script for the 2.0.0 version of octo4a

https://github.com/feelfreelinux/octo4a/blob/master/scripts/setup-klipper-moonraker.sh

By the way i'm still figuring out, how to get it to work i'm running network error.
Maybe you should install 1.2.6 version of octo4a and use the command line you did.

@zaid-hm
Copy link
Author

zaid-hm commented Jul 8, 2024

@Bartouzz did you manage to get it to work, I'm running into a network issue as well

@Bartouzz
Copy link

Bartouzz commented Jul 8, 2024

@zaid-hm Still not ... Starting to lose hope, see my current klippy log:

mcu 'mcu': Starting serial connect
mcu 'mcu': Unable to open serial port: [Errno 13] Could not exclusively lock port /dev/ttyOcto4a: [Errno 13] Permission denied
webhooks client 489798200720: New connection
webhooks client 489798200720: Client info {'program': 'Moonraker', 'version': 'v0.8.0-384-g8f3b30a'}
mcu 'mcu': Unable to open serial port: [Errno 13] Could not exclusively lock port /dev/ttyOcto4a: [Errno 13] Permission denied

seem's like permission problem but i can't find the right answer. i'll post if get something

EDIT: If someone can help...

@schmttc
Copy link

schmttc commented Jul 26, 2024

I'm working on this issue, am updating the klipper install script to work with octo4a 2.0
Once I've done some testing will provide the details for you to confirm.

@schmttc
Copy link

schmttc commented Jul 27, 2024

I've fixed the environment and permission denied error, but have run into the next error (non rooted device) https://github.com/schmttc/octo4a/blob/schmttc-patch-1/scripts/setup-klipper.sh
Have confirmed that Klipper on a Raspberry Pi 3B is working with the printer.

mcu 'mcu': Wait for identify_response
Traceback (most recent call last):
  File "/klipper/klippy/serialhdl.py", line 68, in _get_identify_data
    params = self.send_with_response(msg, 'identify_response')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/klipper/klippy/serialhdl.py", line 262, in send_with_response
    return src.get_response([cmd], self.default_cmd_queue)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/klipper/klippy/serialhdl.py", line 319, in get_response
    self.serial.raw_send_wait_ack(cmds[-1], minclock, reqclock,
  File "/klipper/klippy/serialhdl.py", line 254, in raw_send_wait_ack
    self._error("Serial connection closed")
  File "/klipper/klippy/serialhdl.py", line 61, in _error
    raise error(self.warn_prefix + (msg % params))
serialhdl.error: mcu 'mcu': Serial connection closed

@schmttc schmttc linked a pull request Aug 1, 2024 that will close this issue
@schmttc
Copy link

schmttc commented Aug 1, 2024

I've used setup-klipper-moonraker.sh and reduced it to only install Klipper, which resolves all issues.

Please try https://github.com/schmttc/octo4a/blob/klipper-fix/scripts/setup-klipper.sh

Note, you will get this error in klippy.log if Klipper is not set to the correct serial port, or the printer is not available/powered off. This error will go away once the printer is connected and configured correctly.

mcu 'mcu': Starting serial connect
mcu 'mcu': Timeout on connect
mcu 'mcu': Wait for identify_response
Traceback (most recent call last):
  File "/root/klipper/klippy/serialhdl.py", line 68, in _get_identify_data
    params = self.send_with_response(msg, 'identify_response')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/klipper/klippy/serialhdl.py", line 262, in send_with_response
    return src.get_response([cmd], self.default_cmd_queue)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/klipper/klippy/serialhdl.py", line 319, in get_response
    self.serial.raw_send_wait_ack(cmds[-1], minclock, reqclock,
  File "/root/klipper/klippy/serialhdl.py", line 254, in raw_send_wait_ack
    self._error("Serial connection closed")
  File "/root/klipper/klippy/serialhdl.py", line 61, in _error
    raise error(self.warn_prefix + (msg % params))
serialhdl.error: mcu 'mcu': Serial connection closed

@schmttc
Copy link

schmttc commented Aug 1, 2024

This may need more troubleshooting, while everything kicked off OK either Octoprint or Klipper crashed part way though a test print

@apparle
Copy link

apparle commented Sep 10, 2024

I'm trying to use setup-klipper-moonraker.sh itself and faced similar Permission denied errors.
Based on your pull request, I added LD_PRELOAD=/home/octoprint/ioctl-hook.so while launching klippy.py and now I'm getting errors similar to you. @schmttc how did you solve those errors?

mcu 'mcu': Wait for identify_response

What is connection information in your printer.cfg? Mine is:

[mcu]
serial: /dev/ttyOcto4a
baud: 250000
restart_method: command

Also, I checked that my printer is setup correctly because other devices running Klippy are able to control it.
And FWIW, I'm running Octo4a on a non-rooted Android 11 device -- and that device could control a Marlin-firmware-printer correctly without the extension.

@schmttc
Copy link

schmttc commented Sep 11, 2024

I'm trying to use setup-klipper-moonraker.sh itself and faced similar Permission denied errors. Based on your pull request, I added LD_PRELOAD=/home/octoprint/ioctl-hook.so while launching klippy.py and now I'm getting errors similar to you. @schmttc how did you solve those errors?

mcu 'mcu': Wait for identify_response

What is connection information in your printer.cfg? Mine is:

[mcu]
serial: /dev/ttyOcto4a
baud: 250000
restart_method: command

Also, I checked that my printer is setup correctly because other devices running Klippy are able to control it. And FWIW, I'm running Octo4a on a non-rooted Android 11 device -- and that device could control a Marlin-firmware-printer correctly without the extension.

Sadly I never got to the bottom of this, it worked intermittently a couple of times and then not again.
Same issue on unrooted Android 11 and 13.
Connection works when connecting to a Raspberry Pi 3
MCU config

[mcu]
serial: /dev/ttyOcto4a
restart_method: command

Error

mcu 'mcu': Wait for identify_response
Traceback (most recent call last):
  File "/root/klipper/klippy/serialhdl.py", line 68, in _get_identify_data
    params = self.send_with_response(msg, 'identify_response')
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/klipper/klippy/serialhdl.py", line 262, in send_with_response
    return src.get_response([cmd], self.default_cmd_queue)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/klipper/klippy/serialhdl.py", line 319, in get_response
    self.serial.raw_send_wait_ack(cmds[-1], minclock, reqclock,
  File "/root/klipper/klippy/serialhdl.py", line 254, in raw_send_wait_ack
    self._error("Serial connection closed")
  File "/root/klipper/klippy/serialhdl.py", line 61, in _error
    raise error(self.warn_prefix + (msg % params))
serialhdl.error: mcu 'mcu': Serial connection closed

@schmttc
Copy link

schmttc commented Sep 11, 2024

@apparle I've done some testing, and if you use the older Octo4a app version 1.2.6, it installs the latest Octoprint, and fixes the Klipper issues

@spenc302
Copy link

Find a fix or at least a cause? Tried to roll back to older version of octo4a and it's still giving me permission errors, would a work around be using a rooted device

@akei-ai
Copy link

akei-ai commented Oct 26, 2024

Hello, I got it to work on the main version of Octo4a. The changes I have done is on /mnt/.../klipper/start.sh and adding LD_PRELOAD=/home/octoprint/...

Version: Android 13 (NOT ROOTED)
Device: Asus Zenfone Max Pro M1

Printing is working. I am printing a benchy right now
Edited Files:
/mnt/external/extensions/klipper/start.sh

#!/bin/sh

KLIPPER_ARGS="/root/klipper/klippy/klippy.py /root/printer.cfg -l /root/printer_data/logs/klippy.log -I /root/printer_data/comms/klippy.serial -a >
/root/klipper-venv/bin/python \$KLIPPER_ARGS &
MOONRAKER_ARGS="/root/moonraker/moonraker/moonraker.py -d /root/printer_data"

nginx
LD_PRELOAD=/home/octoprint/ioctl-hook.so /root/klipper-venv/bin/python $KLIPPER_ARGS &
LD_PRELOAD=/home/octoprint/ioctl-hook.so /root/moonraker-venv/bin/python $MOONRAKER_ARGS

~/printer_data/config/printer.cfg

#include mainsail.cfg. Adding the path on printer.cfg for some reasons on my setup breaks moonraker.
[include mainsail.cfg]
...

~/printer_data/config/mainsail.cfg

[virtual_sdcard]
path: ~/printer_data/gcodes

@akei-ai
Copy link

akei-ai commented Oct 26, 2024

Hello, I got it to work on the main version of Octo4a. The changes I have done is on /mnt/.../klipper/start.sh and adding LD_PRELOAD=/home/octoprint/...

Version: Android 13 (NOT ROOTED) Device: Asus Zenfone Max Pro M1

Printing is working. I am printing a benchy right now Edited Files: /mnt/external/extensions/klipper/start.sh

#!/bin/sh

KLIPPER_ARGS="/root/klipper/klippy/klippy.py /root/printer.cfg -l /root/printer_data/logs/klippy.log -I /root/printer_data/comms/klippy.serial -a >
/root/klipper-venv/bin/python \$KLIPPER_ARGS &
MOONRAKER_ARGS="/root/moonraker/moonraker/moonraker.py -d /root/printer_data"

nginx
LD_PRELOAD=/home/octoprint/ioctl-hook.so /root/klipper-venv/bin/python $KLIPPER_ARGS &
LD_PRELOAD=/home/octoprint/ioctl-hook.so /root/moonraker-venv/bin/python $MOONRAKER_ARGS

~/printer_data/config/printer.cfg

#include mainsail.cfg. Adding the path on printer.cfg for some reasons on my setup breaks moonraker.
[include mainsail.cfg]
...

~/printer_data/config/mainsail.cfg

[virtual_sdcard]
path: ~/printer_data/gcodes

Screenshot_20241027_030601
Screenshot_20241027_030512

@apparle
Copy link

apparle commented Oct 28, 2024

@akei-ai can you report which version of the https://github.com/feelfreelinux/octo4a-bootstrap-builder (selected first time octo4a sets up the octoprint server) you got working with Klipper?.
Based on my conversation with @feelfreelinux, he had fixed the ioctl issue in feelfreelinux/octo4a-bootstrap-builder@364ee8b such that klipper can open the device, and I was going to test that fix. But for other reasons, I had to rollback to Marlin firmware on my printer and never got around to testing it.

@akei-ai
Copy link

akei-ai commented Oct 29, 2024

@apparle I got the 2.1.0 version, and the current Octoprint builder 1.10.2-f4f81ac1?

I've gotten it to work on two devices: I haven't tested other devices besides this.
Huawei Y7 (Android 7)
Asus Zenfone Max Pro M1 (Pixel Experience Custom Rom, Android 13)

I think its pretty much in an alpha state right now, Octo4a crashes sometimes when using the klipper+mainsail+moonraker setup but it works pretty much that I'm printing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants