I try to take a screenshot and display it with the following code:
import pyautogui
im = pyautogui.screenshot()
im.show()
but it says in the console Access is denied. and pops a windows error:
same error if i save the picture and try to double click it from the explorer (not with python), but I can open it with sublime text for some reason.
code used for saving:
import pyautogui
import PIL
im = pyautogui.screenshot()
im.save(r'screenshot1.png')
im = PIL.Image.open(r'screenshot1.png')
im.show()
how do i solve this? should i change permissions on taking the screenshot somehow?
You need to change the startup type of your Windows license management service.
Search for "Services" in your computer, and open the Services Management. Find the Windows license management service, and change the startup type to "Automatic". Press "apply" and "ok".
Refer to this for visualization of the process.
Related
TLDR; I have a python script that uses autopygui to click on a file and open it, but it does not work with lnk files located in the same path.
I have a little script using pyautogui to screenshot a desktop icon and save it as a png image on the desktop and doubleclick it to open that image. This works perfect.
However..
I tried implementing the same script on an existing Firefox.lnk shortcut and it fails with the following error:
locateOnScreen Error
Things I have tried:
Running VS code as admin.
locateOnCenterScreen and locateOnScreen.
I have tried others, but I'm blanking because I have tried everything I can think of.
It should open my Firefox.lnk shortcut up, it does not. It only works on png file.
It's because the locateOnScreen(...) function only accepts paths to image files, and .lnk files are not image files. If you manually took a screenshot of the Firefox icon on your desktop, saved it as a PNG file, and passed that to your script, it would open fine.
If you want to launch a program using a .lnk file from Python, you don't need pyautogui at all. Consider using os.startfile(...) instead.
You should put the path of png file in locateCenterOnScreen(...) function instead.
Please also make sure you minimize all active windows so that pyautogui could locate your Firefox short icon.
import pyautogui
pyautogui.hotkey('winleft','d')
icon_location = pyautogui.locateCenterOnScreen('.../FireFox_icon_screenshot.png', confidence=0.9)
pyautogui.moveTo(icon_location)
pyautogui.click(clicks=2)
I tried importing cv2. But When I import it in my python file with ui, it overwrite the code, and it is the first one to run, which supposedly, it should be the other python file. It should just be run when only i click the push button. Kindly help me. :< Beginner here.
Or do you have other ideas on how to play external video like mp4 which is also saved in the same folder.
I'm using qtdesigner, python.
I want to automate putty , i know there is paramiko and other ssh libraries available.
But i want to get logs as if i typed commands manually.
Is it possible to make python script wait till [user#server~]# appears then enter the command.
I am using pyautogui...
I have tried searching pyautogui docs but could not find any .
Is there anything subprocess module can do . I am new to python sorry.
I have tried using image but it is not a good option.
import pyautogui
image = pyautogui.locateOnScreen("image.png")
#Searches for the image
while image == None:
image = pyautogui.locateOnScreen("image.png")
print("still haven't found the image")
I set up PyCharm for remote debugging according to this tutorial on CodeProject
http://www.codeproject.com/Tips/987276/Remote-Programming-of-RaspberryPi-using-PyCharm
I am now wondering if it is possible to execute a Python Script with the help of PyCharm on the RaspberryPI and receive the output in PyCharm. Specifically I want to do some image processing and display the image with the help of OpenCV. It would be great to get the image displayed on my Windows machine, not on the Pi.
Another usecase, I want to create some matplot figure, execute the script on the pi and show the Output back in PyCharm on my Windows machine.
Is this possiple?
Kind Regards
You can do this using OpenCV Image Viewer Plugin. Debug you program using remote interpreter in Pycharm, stop at the breakpoint and choose "View as image".
https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer
Disclaimer: I'm an author of this plugin
I am using wand library in my raspberry project running raspbian and python 2.7.
I have a code part as below to display picture from an url:
with Image(file=urllib2.urlopen(r.text)) as imageOBJ:
display(imageOBJ)
These lines display the image correctly. However, I want this window to stay open and my process to continue with other things in my script. Because after 30 seconds I want to repeat the same thing and change the image in the window. Right now, my code is not running until I close the display window.
Please note that this is not the case on my mac but only on raspberry pi B+ , wheezy raspbian.
How can I prevent this behaviour without closing the image display window?
Thanks in advance
This behavior is expected as both Windows & OS X call the OS's run command start & open respectively -- see reference. On the Raspberry Pi, and other like systems, the wand library calls MagickDisplayImage directly on Python's MainThread.
To emulate like behavior on the Raspberry Pi use the xdg-open utility, and Python's subprocess and tmpfile modules.
Create a temporary file to hold the image
Write image to temporary file
Call xdg-open to open temporary file in an isolated process.
import subprocess, tempfile
from wand.image import Image
with Image(filename='wizard:') as imageOBJ:
tempOBJ = tempfile.NamedTemporaryFile(suffix='.jpg',
prefix='/tmp/myProject-',
delete=False)
imageOBJ.save(file=tempOBJ)
subprocess.call('xdg-open {}'.format(tempOBJ.name), shell=True)
Of course mileage will vary across OS distro/version/desktop-environment.