I am getting this error is this some issue with Apple Silicon Mac? How can I fix?
Traceback (most recent call last):
File "/Users/./PycharmProjects/./main.py", line 18, in <module>
for instance in pyautogui.locateAllOnScreen('Dark.png', confidence=0.1, grayscale=True):
File "/Users/./Library/Python/3.9/lib/python/site-packages/pyautogui/__init__.py", line 175, in wrapper
return wrappedFunction(*args, **kwargs)
File "/Users/./Library/Python/3.9/lib/python/site-packages/pyautogui/__init__.py", line 201, in locateAllOnScreen
return pyscreeze.locateAllOnScreen(*args, **kwargs)
File "/Users/./Library/Python/3.9/lib/python/site-packages/pyscreeze/__init__.py", line 397, in locateAllOnScreen
screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here.
File "/Users/./Library/Python/3.9/lib/python/site-packages/pyscreeze/__init__.py", line 477, in _screenshot_osx
im = Image.open(tmpFilename)
NameError: name 'Image' is not defined
Here is my code
try:
while True:
try:
for instance in pyautogui.locateAllOnScreen('Dark.png', confidence=0.1, grayscale=True):
X, Y = pyautogui.center(instance)
pyautogui.click(X,Y)
except KeyboardInterrupt:
print("Uh-oh")
except KeyboardInterrupt:
print("Uh oh")
Here is pythonautogui's screenshot function. Is it something wrong with the screenshot function or is it my code?
def _screenshot_osx(imageFilename=None, region=None):
"""
TODO
"""
# TODO - use tmp name for this file.
if imageFilename is None:
tmpFilename = 'screenshot%s.png' % (datetime.datetime.now().strftime('%Y-%m%d_%H-%M-%S-%f'))
else:
tmpFilename = imageFilename
subprocess.call(['screencapture', '-x', tmpFilename])
im = Image.open(tmpFilename)
if region is not None:
assert len(region) == 4, 'region argument must be a tuple of four ints'
region = [int(x) for x in region]
im = im.crop((region[0], region[1], region[2] + region[0], region[3] + region[1]))
os.unlink(tmpFilename) # delete image of entire screen to save cropped version
im.save(tmpFilename)
else:
# force loading before unlinking, Image.open() is lazy
im.load()
if imageFilename is None:
os.unlink(tmpFilename)
return im