1

Been looking to get started w/ pyobjc in order to simulate some mouse-events/keystrokes equivalent to ctypes on windows. Ran a clean install of pyobjc (pyobjc-core was downloaded first, then pyobjc). Below is the code that I have been trying out (source):

from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap

def mouseEvent(type, posx, posy):
        theEvent = CGEventCreateMouseEvent(
                    None, 
                    type, 
                    (posx,posy), 
                    kCGMouseButtonLeft)
        CGEventPost(kCGHIDEventTap, theEvent)

def mousemove(posx,posy):
        mouseEvent(kCGEventMouseMoved, 845, 396);

def mouseclick(posx,posy):
        mouseEvent(kCGEventMouseMoved, 845, 396);
        mouseEvent(kCGEventLeftMouseDown, 845, 396);
        mouseEvent(kCGEventLeftMouseUp, 845, 396);

Which yields the following error as most recent:

File "/usr/local/lib/python3.5/site-packages/objc/__init__.py", line 15, in _update
    import objc._objc as _objc
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/objc/_objc.cpython-35m-darwin.so, 2): Symbol not found: _PyObject_REPR
  Referenced from: /usr/local/lib/python3.5/site-packages/objc/_objc.cpython-35m-darwin.so
  Expected in: flat namespace
 in /usr/local/lib/python3.5/site-packages/objc/_objc.cpython-35m-darwin.so

Clearly the issue is that _PyObject_REPR is absent from Python3.5, and so the init script fails. Having gone on the bitbucket 'issues' page, I found this. One of the users (Kentzo) amended the pyobjc github to remove the involvement of _PyObject_REPR.

My question: how do I go about correctly installing his amended version? I have attempted the standard 'pip3 install "link"' method, however I cannot seem to install it over my existing pyobjc files. Do I need to manually remove all of the pyobjc files via sudo?

As you can probably tell I'm a bit of a noob, so any guidance would be much appreciated!

Thanks!

Community
  • 1
  • 1
BotShot
  • 11
  • 2

1 Answers1

0

To install a working version, you will want to download the correct pyobjc version (Kentzo's), navigate to the downloaded folder in terminal or the command line, and run "python3 setup.py install" from terminal (Mac) or "setup.py install" from the command line (Windows). The setup.py file will handle everything for you.

Download Kentzo's version here, and then open it: https://github.com/GreatFruitOmsk/pyobjc-core/releases/download/v3.0.5.dev0/pyobjc-core-3.0.5.tar.gz.

Once you've opened that downloaded folder, follow the instructions from this page under the Distutils section: https://docs.python.org/2/install/#the-new-standard-distutils.

I don't know whether already having the old pyobjc version will cause trouble, but go ahead and uninstall the previous pyobjc version (with pip3 uninstall like usual), and then start the above steps.

WP Lamb
  • 1
  • 1