1

This python (Python 3.7.3) code:

from pynput.keyboard import Listener
import tkinter as tk

def on_press(key):
    pass

with Listener(on_press=on_press) as listener :
    root = tk.Tk()
    root.mainloop()

Fails with the message:

Illegal instruction: 4

My googling hasn't got very far, other than to suggest that it's a problem that appears on OSX (I am running macOS Catalina 10.15.6)

What is causing this error?

EDIT:

On a zsh (rather than bash) I get this:

joe2021@Josephs-Mac-mini mouse-sniper % python3 mcve2.py

zsh: illegal hardware instruction python3 mcve2.py

Both pynput and tkinter work fine seperately which suggests it's not a problem with the libraries...

Joe
  • 4,367
  • 7
  • 33
  • 52
  • 2
    This? ["Illegal instruction: 4" when trying to start Python with virtualenv in OS X](https://stackoverflow.com/q/33754660/1364007) – Wai Ha Lee Nov 03 '21 at 09:54
  • 1
    Can confirm no errors with your code on windows. – DNy Nov 03 '21 at 09:56
  • 1
    @waiHaLee - that's the same error, but I'm not using virtualenv (I'm also mostly interested in finding out more why and how the error occured, which those answers do not cover) – Joe Nov 03 '21 at 10:02
  • Can you paste full stacktrace ? – Philippe Nov 03 '21 at 13:18
  • @Philippe - literally the whole output is "Illegal instruction: 4" :s – Joe Nov 03 '21 at 15:42
  • How did you run the script ? Can you show the result of he command `python -V` ? – Philippe Nov 03 '21 at 16:25
  • 2
    @Joe Even though you’re not using virtualenv, the underlying issue is the same: some native library file is broken and needs to be reinstalled. The safest route might be to delete all related libraries and reinstall them from scratch. If the problem persists, file a bug report with the maintainers of the binary packages. – Konrad Rudolph Nov 04 '21 at 13:45
  • Is your Mac using a M1 chip? If so, this is very normal: something you're using was compiled with CPU extensions Rosetta doesn't know how to emulate. – Charles Duffy Nov 04 '21 at 14:10

0 Answers0