keyboard icon indicating copy to clipboard operation
keyboard copied to clipboard

Trouble Importing module on Mac OS Monterey

Open Ashrit-Yarava opened this issue 4 years ago • 13 comments

Importing the module fails. error.txt

Ashrit-Yarava avatar Jan 07 '22 02:01 Ashrit-Yarava

Known issue, I get the same, it may be because of the M1 chip

BytePhoenixCoding avatar Jan 07 '22 11:01 BytePhoenixCoding

Same issue here on Mac OS Big Sur. I have an M1 chip though which seems to be the source of the cause.

Vespertilo avatar Jan 11 '22 23:01 Vespertilo

Same here, Mac OS Monterey (M1 chip)

However, for me, I get a segfault when importing the library:

python
Python 3.9.10 (main, Jan 15 2022, 11:40:53) 
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import keyboard
zsh: segmentation fault  python

alaninnovates avatar Jan 18 '22 18:01 alaninnovates

I too receive the segmentation fault error. Any alternatives or ETA is known? PythonCrash

rasoolmohammedy avatar Mar 03 '22 14:03 rasoolmohammedy

same here, segmentation fault error whenever I try to run a program with import keyboard

ghost avatar Mar 06 '22 17:03 ghost

It uses ctypes, so it needs an update before supporting an ARM-based CPU like M1.

Unfortunately I don't have a Mac to develop on, so I rely 100% on community contributions for Mac support :(

boppreh avatar Mar 06 '22 17:03 boppreh

Hi @boppreh, I have Mac M1 without Rosetta i.e. ARM64 architecture type. Can you please assist me on how and where to make the changes?

rasoolmohammedy avatar Mar 06 '22 18:03 rasoolmohammedy

@rasoolmohammedy It's somewhere in https://github.com/boppreh/keyboard/blob/master/keyboard/_darwinkeyboard.py , though where exactly needs more testing.

Some places that could be:

It'd suggest it running it with pydb step by step during initialization. That should tell you which of the above are causing problems.

boppreh avatar Mar 06 '22 18:03 boppreh

@Ashrit-Yarava @rasoolmohammedy from python 3.10.2 onwards universal binaries are provided, so that if you are facing an issue with importing modules that crash on segmentation fault you can simply run your program likewise python3-intel64 yourprogram.py I tried this with a program that imports keyboard and I faced no problem at all.

from Python 3.10.2 changelog:

" Provide “python3.x-intel64” executable to allow reliably forcing macOS universal2 framework builds to run under Rosetta 2 Intel-64 emulation on Apple Silicon Macs. This can be useful for testing or when universal2 wheels are not yet available. "

ghost avatar Mar 06 '22 19:03 ghost

Hi @4sito ,

Thank you for your comment, the problem what we have right now is, we don't have Rosetta emulator installed on Mac M1 hence we will not be able to run python3-intel64 :(

rasoolmohammedy avatar Mar 06 '22 19:03 rasoolmohammedy

@rasoolmohammedy, sorry but Rosetta should automatically install anytime you try to run an x86 application, I had my M1 Mac for more than a year now, but IIRC there shouldn't be any problem installing Rosetta, as it is an automatic process, other than that unfortuntely I don't know how to help you furthermore

ghost avatar Mar 07 '22 05:03 ghost

Hi @4sito,

Thank you for your comment. In our case, it is mandatory to run our automation suite without Rosetta. that is our precondition. With rosetta this module works absolutely fine till date.

rasoolmohammedy avatar Mar 07 '22 10:03 rasoolmohammedy

@rasoolmohammedy oh ok, didn't knew that, unfortunately I can't help you if that's the problem

ghost avatar Mar 07 '22 11:03 ghost