I went round the houses for weeks with this one. The solutions above did not work for me.
The sequence of terminal commands that finally got "Quartz" to work for me on a M2 Mac Sequoia 15.3.2 was the following:
pip install --upgrade pip
pip install pyobjc-framework-Quartz
pip install pyobjc
python3 -m pip install pyautogui
The key reference is at: https://pyautogui.readthedocs.io/en/latest/install.html
My script contained:
#!/bin/zsh
from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventCreate
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import CGEventGetLocation
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
import Quartz
import sys
import time
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy)
def mouseclickdn(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy)
def mouseclickup(posx,posy):
mouseEvent(kCGEventLeftMouseUp, posx,posy)
def mousedrag(posx,posy):
mouseEvent(kCGEventLeftMouseDragged, posx,posy)
and the error message before the solution was:
Traceback (most recent call last):
File "wmap1.py", line 2, in <module>
from Quartz.CoreGraphics import CGEventCreateMouseEvent
ModuleNotFoundError: No module named 'Quartz'