英文:
How to fix 'TypeError: '<' not supported between instances of 'str' and 'int' when running pyautogui.locateOnScreen()?
问题
I'm writing a program that would be able to detect the shiny sprite of whatever pokemon that I'm hunting. However, whenever I run pyautogui.locateOnScreen()
, I raise a TypeError: '<' not supported between instances of 'str' and 'int'.
import pyautogui as pag
pag.locateOnScreen('beldum.png')
I also took the screenshot of the image myself, but I heard that using pyautogui's own screenshot function is better. I tried doing this, but I get the same type error whenever I try to do it.
Here are the tracebacks that I got.
Traceback (most recent call last):
File "/path/to/file", line 3, in <module>
pag.locateOnScreen('beldum.png')
File "/path/to/venv/lib/python3.11/site-packages/pyautogui/__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)
File "/path/to/venv/lib/python3.11/site-packages/pyautogui/__init__.py", line 210, in locateOnScreen
return pyscreeze.locateOnScreen(*args, **kwargs)
File "/path/to/venv/lib/python3.11/site-packages/pyscreeze/__init__.py", line 375, in locateOnScreen
screenshotIm = screenshot(
File "/path/to/venv/lib/python3.11/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'
英文:
im writing a program that would be able to detect the shiny sprite of whatever pokemon that im hunting, however, whenever i run pyautogui.locateOnScreen() i raise a TypeError: '<' not supported between instances of 'str' and 'int'
import pyautogui as pag
pag.locateOnScreen('beldum.png')
i also took the screenshot of the image myself, but i heard that using pyautogui's own screenshot function is better. i tried doing this, but i get the same type error whenever i try to do it.
Here are the tracebacks that I got.
Traceback (most recent call last):
File "/path/to/file", line 3, in <module>
pag.locateOnScreen('beldum.png')
File "/path/to/venv/lib/python3.11/site-packages/pyautogui/__init__.py", line 172, in wrapper
return wrappedFunction(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/pyautogui/__init__.py", line 210, in locateOnScreen
return pyscreeze.locateOnScreen(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/site-packages/pyscreeze/__init__.py", line 375, in locateOnScreen
screenshotIm = screenshot(
^^^^^^^^^^^
File "/path/to/venv/lib/python3.11/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
得分: 19
I had the same problem when using pyautogui. I'm using Python 3.8, and the version of pyautogui is 9.5.0. Actually, this is a bug in the Python framework packages. I don't know if Python 3.11 works the same way. Anyway, this is how I met this problem and fixed it.
I have this error report:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyscreeze/__init__.py", line 528, in _screenshot_osx
if tuple(PIL__version__) < (6, 2, 1):
TypeError: '<' not supported between instances of 'str' and 'int'
Then I clicked into this report file and and trace back the value of PIL__version__
. It's defined like this: __version__ = "9.5.0"
Now we find the problem. A simple test program can tell you everything:
__version__ = "9.5.0"
print(tuple(__version__))
print(type(tuple(__version__)))
print((6, 2, 1))
print(type((6,2,1)))
The output you'll get looks like this:
('9', '.', '5', '.', '0')
<class 'tuple'>
(6, 2, 1)
<class 'tuple'>
They are both tuples, but the elements inside this tuple are str
and int
types. Of course they can't be compared.
So you need to click into the reported error file. Replace this code:
if tuple(PIL__version__) < (6, 2, 1):
with this code:
if tuple(map(int, PIL__version__.split("."))) < (6, 2, 1):
Now everything should work fine.
英文:
I had the same problem when using pyautogui. I'm using Python 3.8, and the version of pyautogui is 9.5.0. Actually, this is a bug in the Python framework packages. I don't know if Python 3.11 works the same way. Anyway, this is how I met this problem and fixed it.
I have this error report:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyscreeze/__init__.py", line 528, in _screenshot_osx
if tuple(PIL__version__) < (6, 2, 1):
TypeError: '<' not supported between instances of 'str' and 'int'
Then I clicked into this report file and and trace back the value of PIL__version__
. It's defined like this: __version__ = "9.5.0"
Now we find the problem. A simple test program can tell you everything:
__version__ = "9.5.0"
print(tuple(__version__))
print(type(tuple(__version__)))
print((6, 2, 1))
print(type((6,2,1)))
The output you'll get looks like this:
('9', '.', '5', '.', '0')
<class 'tuple'>
(6, 2, 1)
<class 'tuple'>
They are both tuples, but the elements inside this tuple are str
and int
types. Of course they can't be compared.
So you need to click into the reported error file. Replace this code:
if tuple(PIL__version__) < (6, 2, 1):
with this code:
if tuple(map(int, PIL__version__.split("."))) < (6, 2, 1):
Now everything should work fine.
答案2
得分: 7
你也可以在启动时对其进行修补:
import pyscreeze
import PIL
__PIL_TUPLE_VERSION = tuple(int(x) for x in PIL.__version__.split("."))
pyscreeze.PIL__version__ = __PIL_TUPLE_VERSION
<您的应用程序的其余部分>
免责声明:这对某些边缘情况可能不起作用,并且也可能因为pyscreeze
的代码更改而导致故障。
英文:
You can also patch it on startup :
import pyscreeze
import PIL
__PIL_TUPLE_VERSION = tuple(int(x) for x in PIL.__version__.split("."))
pyscreeze.PIL__version__ = __PIL_TUPLE_VERSION
<rest of your app>
Disclaimer this won't work on some edge cases. and can also break due to code changes on pyscreeze
答案3
得分: 0
-
打开位于路径
/path/to/venv/lib/python3.11/site-packages/pyscreeze/__init__.py
的__init__.py
文件。 -
将第 527 行的代码替换为:
if tuple([int(x) for x in PIL__version__.split(".")]) < (6, 2, 1):
-
保存文件。
我遇到了同样的问题,这些步骤对我有用。希望对你也有帮助。
英文:
You can try this following
1.Open a __init__.py
in your path "/path/to/venv/lib/python3.11/site-packages/pyscreeze/__init__.py"
.
On the Spyder or the other.
2.You just replace this code in line 527
if tuple(PIL__version__) < (6, 2, 1):
with
if tuple([int(x) for x in PIL__version__.split(".")])< (6, 2, 1):
3.Save the file.
I have the same problem and these step work for me. Hope it's useful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论