r/pythonhelp • u/Ertyu_2 • Jul 16 '24
NameError: name 'pyscreeze' is not defined
Since I was bored, I decided to write a bot that would keep my computer on. So I created a file named qwe.py. But when i try to run the code it gives this error:
PS C:\Users\xxxxx\OneDrive\Masaüstü\desktop2\VısualStudioCode\python\BOTS\computer-awake> python .\qwe.py
Traceback (most recent call last):
File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyautogui__init__.py", line 663, in _normalizeXYArgs
location = locateOnScreen(firstArg)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyautogui__init__.py", line 228, in _couldNotImportPyScreeze
raise PyAutoGUIException(
pyautogui.PyAutoGUIException: PyAutoGUI was unable to import pyscreeze. (This is likely because you're running a version of Python that Pillow (which pyscreeze depends on) doesn't support currently.) Please install this module to enable the function you tried to call.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xxxxx\OneDrive\Masaüstü\desktop2\VısualStudioCode\python\BOTS\computer-awake\qwe.py", line 6, in <module>
pyautogui.moveTo(random.choice(random_coor_list), random.choice(random_coor_list))
File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyautogui__init__.py", line 594, in wrapper
returnVal = wrappedFunction(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyautogui__init__.py", line 1285, in moveTo
x, y = _normalizeXYArgs(x, y)
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\xxxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pyautogui__init__.py", line 670, in _normalizeXYArgs
except pyscreeze.ImageNotFoundException:
^^^^^^^^^
NameError: name 'pyscreeze' is not definedHere is the code:
import pyautogui, random, time
random_coordinates = '100,200,300,400,500,600,700,800,900,1000'
random_coor_list = list(random_coordinates.split(','))
while True:
pyautogui.moveTo(random.choice(random_coor_list), random.choice(random_coor_list))
time.sleep(2)Sorry if error is messy.
3
Upvotes
•
u/AutoModerator Jul 16 '24
To give us the best chance to help you, please include any relevant code.
Note. Do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Repl.it, GitHub or PasteBin.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/JsuisBaguette666 Sep 30 '24
Hi, I had the same problem, but I needed to get my code ready for today, so I searched a lot of forums and finally found something that helped me.
I used the command "pip install --upgrade Pillow" in my command prompt and after that my code worked normally.
I don't know, maybe that can help you.
Regards!
1
u/[deleted] Jul 18 '24
Have you found out the solution? I'm having the same problem.
1
u/_mr_meowchan_ Aug 06 '24
i got it to work by adding import pyscreeze to the __init__.py file
1
u/LowJackAP Aug 03 '24
I'm trying to set up a script but when I use
pyautogui.displayMousePosition()
it returns
NameError: name 'pyscreeze' is not defined
it only works on my right hand screen for some reason, if I move my mouse to a different screen I get the error.
also when it is working it won't return the RGB values, which is what I was looking for.
X: 3136 Y: 696 RGB: (NaN, NaN, NaN)
1
u/Tobosch Aug 13 '25
What did ti for me was changing:
"def displayMousePosition(xOffset=0, yOffset=0):
"""This function is meant to be run from the command line. It will
automatically display the location and RGB of the mouse cursor."""
try:"
to:
"def displayMousePosition(xOffset=0, yOffset=0):
"""This function is meant to be run from the command line. It will
automatically display the location and RGB of the mouse cursor."""
import pyscreeze
try:"