"Wrong version of PyObjC C API" -> updated pyobjc -> AttributeError: CFMachPortCreateRunLoopSource
dbieber opened this issue ยท 11 comments
I just installed aw-watcher-input with poetry.
When I run aw-watcher-input --help
I get RuntimeError: Wrong version of PyObjC C API (got 21, expected 20)
.
What would be required to update aw-watcher-input to work with version 21?
Here's the full stacktrace:
Traceback (most recent call last):
File "/Users/dbieber/.virtualenvs/aw/bin/aw-watcher-input", line 2, in <module>
from aw_watcher_input.main import main
File "/Users/dbieber/code/github/ActivityWatch/aw-watcher-input/src/aw_watcher_input/__init__.py", line 1, in <module>
from . import main
File "/Users/dbieber/code/github/ActivityWatch/aw-watcher-input/src/aw_watcher_input/main.py", line 9, in <module>
from aw_watcher_afk.listeners import KeyboardListener, MouseListener
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/aw_watcher_afk/__init__.py", line 1, in <module>
from . import __main__
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/aw_watcher_afk/__main__.py", line 5, in <module>
from aw_watcher_afk.afk import AFKWatcher
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/aw_watcher_afk/afk.py", line 17, in <module>
from .macos import seconds_since_last_input
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/aw_watcher_afk/macos.py", line 2, in <module>
from Quartz.CoreGraphics import (CGEventSourceSecondsSinceLastEventType,
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/__init__.py", line 102, in <module>
_load()
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/__init__.py", line 28, in _load
from Quartz import CoreGraphics as m
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/CoreGraphics/__init__.py", line 143, in <module>
_load(mod)
File "/Users/dbieber/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/CoreGraphics/__init__.py", line 51, in _load
import Quartz.CoreGraphics._callbacks as m
RuntimeError: Wrong version of PyObjC C API (got 21, expected 20)
This issue seems to originate in aw-watcher-afk (which depends on pyobjc). It's been breaking the CI for aw-watcher-afk for some time now, hopefully all that's needed is to update pyobjc.
If this CI run passes, then I've fixed it, and I'll update aw-watcher-input in just a moment :)
aw-watcher-afk CI run passed! Fixed for aw-watcher-input in a6730e2
Thanks for reporting ๐
Thanks for your impressively prompt turn around fixing this! ๐
Hmm, even after updating to a6730e2 I still get the same error.
> pip freeze | grep aw
aw-client @ file:///Users/dbieber/.virtualenvs/aw/src/aw-client
aw-core @ file:///Users/dbieber/.virtualenvs/aw/src/aw-core
aw-qt==0.1.0
aw-server==0.9
aw-watcher-afk @ file:///Users/dbieber/.virtualenvs/aw/src/aw-watcher-afk
aw-watcher-input==0.1.0
aw-watcher-window==0.2.0
timeslot @ file:///Users/dbieber/.virtualenvs/aw/src/timeslot
@dbieber Can you give me pip freeze | grep pyobjc
? Did you run poetry install
again?
If you have the latest pyobjc, it should work (otherwise I'm clueless).
Installing in a fresh virtualenv resolved the issue,
now it starts but with these errors:
> aw-watcher-input
INFO:aw_watcher_input.main:Starting watcher...
Exception in thread Thread-3:
Traceback (most recent call last):
File "/usr/local/opt/python@3.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.7/site-packages/pymouse/mac.py", line 113, in run
loopsource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.7/site-packages/objc/_lazyimport.py", line 207, in __getattr__
raise AttributeError(name)
AttributeError: CFMachPortCreateRunLoopSource
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:No new input
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/opt/python@3.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.7/site-packages/pykeyboard/mac.py", line 221, in run
Quartz.CFRunLoopRunInMode(Quartz.kCFRunLoopDefaultMode, 5, False)
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.7/site-packages/pykeyboard/mac.py", line 258, in handler
self.key_press(key)
AttributeError: 'KeyboardListener' object has no attribute 'key_press'
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:No new input
From the "working" virtualenv, here's the output of the requested command:
> pip freeze | grep pyobjc
pyobjc-core @ file:///Users/dbieber/Library/Caches/pypoetry/artifacts/b2/19/4f/005efdc28d19ef087a5e3b3785852305ba8d5d46460f72b9b271c65031/pyobjc_core-7.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
pyobjc-framework-Cocoa @ file:///Users/dbieber/Library/Caches/pypoetry/artifacts/e3/5b/6b/dd2dd93f4f528accbd314034720928c813b88865856ada4833032ba147/pyobjc_framework_Cocoa-7.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
pyobjc-framework-Quartz @ file:///Users/dbieber/Library/Caches/pypoetry/artifacts/75/a2/a2/96a923d37185a4a47deec56474de67a9edefcc98673e5d12467d40d038/pyobjc_framework_Quartz-7.0.1-cp37-cp37m-macosx_10_9_x86_64.whl
And yes I did poetry install again.
Huh, that's new. Might be caused by the v21 API/bumping pyobjc to 7.0. It presumably affects aw-watcher-afk as well.
Edit: It does not affect aw-watcher-afk since it's been upgraded to use CGEventSourceSecondsSinceLastEventType
: https://github.com/ActivityWatch/aw-watcher-afk/blob/master/aw_watcher_afk/macos.py
@dbieber I've opened an issue in the PyUserInput repo PyUserInput/PyUserInput#61. It looks like an easy fix, but I might be wrong about that.
If you have the time, feel free to give it a shot. Otherwise, I might look into it myself in a few weeks.
Thanks for looking into it. Iโll let you know if I get a chance to look into it myself before then.
I logged my progress in PyUserInput/PyUserInput#61.
Switching to Python 3.9 (not sure if necessary) and rolling jedi
back to version 0.17.2 partially resolved the issue; now its successfully logging mouse moves. No changes were needed to aw-watcher-input or PyUserInput for this.
Still gives the CFMachPortCreateRunLoopSource
AttributeError.
> aw-watcher-input
INFO:aw_watcher_input.main:Starting watcher...
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.9/3.9.1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.9/site-packages/pykeyboard/mac.py", line 215, in run
loopsource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
File "/Users/dbieber/.virtualenvs/aw-watcher-input/lib/python3.9/site-packages/objc/_lazyimport.py", line 207, in __getattr__
raise AttributeError(name)
AttributeError: CFMachPortCreateRunLoopSource
INFO:aw_watcher_input.main:No new input
INFO:aw_watcher_input.main:New input: {'id': None, 'timestamp': datetime.datetime(2020, 12, 30, 17, 59, 12, 131000, tzinfo=datetime.timezone.utc), 'duration': datetime.timedelta(seconds=1, microseconds=13449), 'data': {'presses': 0, 'clicks': 0, 'deltaX': 10.9921875, 'deltaY': 53.1328125}}
INFO:aw_watcher_input.main:New input: {'id': None, 'timestamp': datetime.datetime(2020, 12, 30, 17, 59, 13, 144000, tzinfo=datetime.timezone.utc), 'duration': datetime.timedelta(seconds=1, microseconds=6188), 'data': {'presses': 0, 'clicks': 0, 'deltaX': 165.3203125, 'deltaY': 204.9375}}
The logging of mouse data seems intermittent, and isn't showing up again on subsequent runs.