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

"Wrong version of PyObjC C API" -> updated pyobjc -> AttributeError: CFMachPortCreateRunLoopSource #2

Open
dbieber opened this issue Dec 28, 2020 · 11 comments

Comments

@dbieber
Copy link

dbieber commented Dec 28, 2020

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)
@ErikBjare
Copy link
Member

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 :)

@ErikBjare
Copy link
Member

aw-watcher-afk CI run passed! Fixed for aw-watcher-input in a6730e2

Thanks for reporting 🙂

@dbieber
Copy link
Author

dbieber commented Dec 28, 2020

Thanks for your impressively prompt turn around fixing this! 🙏

@ErikBjare
Copy link
Member

@dbieber You're just lucky, I was just about to stop working for the day 😉

@dbieber
Copy link
Author

dbieber commented Dec 28, 2020

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

@ErikBjare
Copy link
Member

@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).

@dbieber
Copy link
Author

dbieber commented Dec 28, 2020

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/[email protected]/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/[email protected]/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.

@ErikBjare
Copy link
Member

ErikBjare commented Dec 30, 2020

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

@ErikBjare
Copy link
Member

@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.

@ErikBjare ErikBjare changed the title "Wrong version of PyObjC C API (got 21, expected 20)" "Wrong version of PyObjC C API" -> updated pyobjc -> AttributeError: CFMachPortCreateRunLoopSource Dec 30, 2020
@dbieber
Copy link
Author

dbieber commented Dec 30, 2020

Thanks for looking into it. I’ll let you know if I get a chance to look into it myself before then.

@dbieber
Copy link
Author

dbieber commented Dec 30, 2020

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/[email protected]/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.

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

No branches or pull requests

2 participants