PyUserInput/PyUserInput

Broken with pyobjc 7.0

ErikBjare opened this issue · 4 comments

See this issue: ActivityWatch/aw-watcher-input#2

Looks like CFMachPortCreateRunLoopSource has moved from Quartz to CoreFoundation.

[Ignore this whole comment. The 3.7.9 results in particular are from the virtualenv I was having trouble with in a previous issue.]

Here are the results of my running "import Quartz" in Python 3.7.9 and Python 3.9.1

Python 3.7.9 (default, Nov 20 2020, 18:45:38) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import Quartz
^[[A^[[A---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-16fa639852e6> in <module>
----> 1 import Quartz

~/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/__init__.py in <module>
    100 
    101 
--> 102 _load()

~/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/__init__.py in _load()
     26 
     27     try:
---> 28         from Quartz import CoreGraphics as m
     29 
     30         submods.append(m)

~/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/CoreGraphics/__init__.py in <module>
    141 
    142 
--> 143 _load(mod)

~/.virtualenvs/aw/lib/python3.7/site-packages/Quartz/CoreGraphics/__init__.py in _load(mod)
     49         mod.CGFLOAT_MAX = 1.797_693_134_862_315_7e308
     50 
---> 51     import Quartz.CoreGraphics._callbacks as m
     52 
     53     for nm in dir(m):

RuntimeError: Wrong version of PyObjC C API (got 21, expected 20)

In 3.9.1

> ipython
Python 3.9.1 (default, Dec 10 2020, 10:36:35) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import Quartz

In [2]: Quartz.CFMachPortCreateRunLoopSource
Out[2]: <objc.function 'CFMachPortCreateRunLoopSource' at 0x10fdcb530>

In 3.9.1 Quartz.CFMachPortCreateRunLoopSource does exist, so probably OK to close this issue depending on what Python versions you intend to support.

I was using 3.7 in order to build ActivityWatch. I will now try 3.9.1 for building aw-watcher-input.

This did not resolve the issue.

> 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

I've rolled jedi back a version with pip install jedi==0.17.2 and this does seem to have helped somewhat. aw-watcher-input now logs mouse moves. Got this idea from ipython/ipython#12740 after seeing errors with tab completion in my latest installation of ipython.

Still gives the AttributeError: CFMachPortCreateRunLoopSource error on startup though.

Update: the behavior seems intermittent, and the jedi rollback was likely unrelated.

As noted in the readme, this library is unmaintained, and it would be better to use Pynput instead. You are of course welcome to maintain your own forks or take over development if you're really interested.