英文:
pyautogui not working on MacOS ('<' not supported between instances of 'str' and 'int')
问题 {#heading}
以下是您的代码部分的翻译:
import pyautogui
img = 'name.png'
img = pyautogui.locateCenterOnScreen(img)
错误信息的翻译:
Traceback (most recent call last):
File "/Users/cliente/Documents/Personal/dofusBot/bot.py", line 9, in <module>
img = pyautogui.locateCenterOnScreen(img)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyautogui/__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyautogui/__init__.py", line 204, in locateCenterOnScreen
return pyscreeze.locateCenterOnScreen(*args, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 420, in locateCenterOnScreen
coords = locateOnScreen(image, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 375, in locateOnScreen
screenshotIm = screenshot(
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 527, in _screenshot_osx
if tuple(PIL__version__) < (6, 2, 1):
TypeError: '<' not supported between instances of 'str' and 'int'
请注意,由于代码部分并没有需要翻译的内容,我只提供了您请求的翻译部分。如果您需要进一步的帮助或解决错误,请提出具体问题。 英文:
I`m trying to find an image on the screen using pyautoGUI on MacOS. The code i use is the following:
import pyautogui
img = \'name.png\'
`img = pyautogui.locateCenterOnScreen(img)
`
Can anyone help me? I was expecting to get the coordinates of the image, instead i got the error:
Traceback (most recent call last):
File "/Users/cliente/Documents/Personal/dofusBot/bot.py", line 9, in <module>
img = pyautogui.locateCenterOnScreen(img)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyautogui/__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyautogui/__init__.py", line 204, in locateCenterOnScreen
return pyscreeze.locateCenterOnScreen(*args, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 420, in locateCenterOnScreen
coords = locateOnScreen(image, **kwargs)
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 375, in locateOnScreen
screenshotIm = screenshot(
File "/Users/cliente/miniconda/envs/analytics/lib/python3.10/site-packages/pyscreeze/__init__.py", line 527, in _screenshot_osx
if tuple(PIL__version__) < (6, 2, 1):
TypeError: '<' not supported between instances of 'str' and 'int'
答案1 {#1}
得分: 1
这似乎只是由于pyscreeze没有跟上Pillow库(PIL)最近几年的更新而导致的一个"bug",并且对该库中版本变量的定义做出了错误的假设。
pyscreeze的开发者似乎在2个月前通过提交eeca245a135cf171c163b3691300138518efa64e来解决了这个问题,但尚未发布新版本。您可以从源代码安装pyscreeze,或者暗中修补您的安装(只需修改一个__init__.py
文件)。
如果降级Pillow几个版本也可能会起作用(但我不确定您需要回退多远。可能不会比6.2.1更早,但那已经是4年前的版本了)。 英文:
This just looks like a "bug" in pyscreeze due to it not keeping up with the past few years of updates to the Pillow library (PIL) and makes a faulty assumption on how the version variable is defined in that library.
The developer of pyscreeze seems to have addressed this 2 months ago in commit eeca245a135cf171c163b3691300138518efa64e but have not yet made any new release. You could install pyscreeze from source, or just sneakily patch your installation (it's just one __init__.py
file).
It might also work if you downgrade Pillow a few versions (but I'm not sure how far back you need to go. Presumably no further than 6.2.1, but that's 4 years old).