Open rimmi2002 opened 6 years ago
It's telling you that it can't find the screencapture
command.
You're running in OS X, correct? What happens when you run screencapture
in Terminal?
Screen capture command works fine in terminal. I am using macosx 10.12.6
Did you ever figure out how to fix this?
Is there any update on this?
I ended up using the pyautogui.locate() function, that seemed to work for me.
I am having this issue when I try to run my code from systemd, else it works perfectly, if i do not.
Can anyone advise what i need to do so that when it runs as systemd it runs the way it should. Thanks
Hi all, I believe the screenshot saves to whatever is the current directory. I don't experience any issues when using it.
As an example: Here is a copy pasta script Try something like this:
# Import the os module & pyautogui
import os
import pyautogui
# 1 Set the file name
filename = 'test2342342.png'
# 2 Print the current working directory
print("Current working directory: {0}".format(os.getcwd()))
# 3 Change the current working directory to home
current_home = os.path.expanduser('~')
os.chdir(current_home)
print("Current working directory: {0}".format(os.getcwd()))
# 4 Take a Screenshot
im1 = pyautogui.screenshot()
im1.save(filename)
# 5 Check current path and if the file exists
current_path = os.path.realpath('.')
path_to_file = os.path.join(current_path, filename)
if exists(path_to_file):
print('Success Image Found At: {}'.format(path_to_file))
else:
print('Failed Image Not Found At: {}'.format(path_to_file))
# Change the current working directory to temp and check for the file again.
os.chdir('/tmp')
current_path = os.path.realpath('.')
path_to_file = os.path.join(current_path, filename)
if exists(path_to_file):
print('Success Image Found At: {}'.format(path_to_file))
else:
print('Failed Image Not Found At: {}'.format(path_to_file))
Hope it helps! Have a Great Day All!
I'm trying to use the following line:
pyautogui.locateOnScreen('Amazonsearch.png')
but I get the following error: 'Traceback (most recent call last): File "/Volumes/3TB Storage/Downloads/Test Python", line 5, in
pyautogui.locateOnScreen('Amazonsearch.png')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyscreeze/init.py", line 265, in locateOnScreen
screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region here.
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyscreeze/init.py", line 327, in _screenshot_osx
subprocess.call(['screencapture', '-x', tmpFilename])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1333, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'screencapture'
[Finished in 0.5s]'
what is the reason for this error? How can a correct it. Thanks.