PyAutoGui - screencapture: cannot write file to intended destination - python

I am trying to find an image on my screen, however it it cannot seem to even save the screenshot? Any ideas?
code:
pyautogui.locateOnScreen('images/toolbox.jpg')
Error:
screencapture: cannot write file to intended destination, .screenshot2018-1106_00-06-22-111441.png
Traceback (most recent call last):
File "/Users/dirk/Desktop/firsttry/test.py", line 103, in <module>
a = pyautogui.locateOnScreen('images/toolbox.jpg')
File "/Users/dirk/Library/Python/2.7/lib/python/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 "/Users/dirk/Library/Python/2.7/lib/python/site-packages/pyscreeze/__init__.py", line 331, in _screenshot_osx
im = Image.open(tmpFilename)
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 2609, in open
fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: '.screenshot2018-1106_00-06-22-111441.png'
[Finished in 0.8s with exit code 1]
[shell_cmd: python -u "/Users/dirk/Desktop/firstry/test.py"]
[dir: /Users/dirk/Desktop/firsttry]
[path: /opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.7/bin:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

Go to pyscreeze/__init__.py (located either in virutalenv or inside your python folder) file, eg: "/Users/dirk/Library/Python/2.7/lib/python/site-packages/pyscreeze/__init__.py"
Navigate to line 327 or 331, inside function: def _screenshot_osx
Remove the . symbol in tempFilename = '.screenshot%s.png', so it should look like tempFilename = 'screenshot%s.png'

Related

Python Exiftool get metadata from livestream

I am trying to read geotagging data from a live stream online, here is my code:
import exiftool
def getVideo(url):
with exiftool.ExifToolHelper() as et:
metadata = et.getmetadata(url)
print(metadata)
getVideo("url/to/stream")
however, I got this error:
Traceback (most recent call last):
File "C:\Users\alexa\Documents\vtest2.py", line 9, in <module>
getVideo("url/to/stream")
File "C:\Users\alexa\Documents\vtest2.py", line 4, in getVideo
with exiftool.ExifToolHelper() as et:
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\exiftool\helper.py", line 101, in __init__
super().__init__(**kwargs)
File "C:\Python311\Lib\site-packages\exiftool\exiftool.py", line 300, in __init__
self.executable = executable or constants.DEFAULT_EXECUTABLE
^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\exiftool\exiftool.py", line 374, in executable
raise FileNotFoundError(f'"{new_executable}" is not found, on path or as absolute path')
FileNotFoundError: "exiftool.exe" is not found, on path or as absolute path
is there a better way to read metadata from a live stream?

FileNotFoundError: [WinError 2] The system cannot find the file specified using whisper

I've been trying to use OpenAI's whisper to transcribe some text.
Whenever I run, I get a FileNotFounderror.
My code is as follows:
import whisper
import os
print(os.listdir())
# f = open('test_text.txt', 'r')
# content = f. read()
# print(content)
# f. close()
audio = 'Users/geoff/Downloads/micro-machines.wav'
model = whisper.load_model("tiny")
result = model.transcribe('micro-machines.wav', fp16=False)
print(result['text'])
The commented out part with the opening of the text file was done as a test and runs each time without issue.
When the code prints the directory, I get the following correct list of files, But then the error follows immediarely after:
['.idea', 'main.py', 'micro-machines.wav', 'test_text.txt', 'venv']
Traceback (most recent call last):
File "C:\Users\geoff\PycharmProjects\pythonProject3\main.py", line 16, in <module>
result = model.transcribe('micro-machines.wav', fp16=False)
File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\transcribe.py", line 82, in transcribe
mel = log_mel_spectrogram(audio)
File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\audio.py", line 111, in log_mel_spectrogram
audio = load_audio(audio)
File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\whisper\audio.py", line 42, in load_audio
ffmpeg.input(file, threads=0)
File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\ffmpeg\_run.py", line 313, in run
process = run_async(
File "C:\Users\geoff\PycharmProjects\pythonProject3\venv\lib\site-packages\ffmpeg\_run.py", line 284, in run_async
return subprocess.Popen(
File "C:\Users\geoff\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\geoff\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
There seems to be a mismatch in the file paths you've used for the commented part as observed from the output:
C:\Users\geoff\ PycharmProjects \ pythonProject3
and the following part.
audio = 'Users/geoff/Downloads/micro-machines.wav'
You may verify where the .wav file exists - in 'Downloads' or in 'pythonProject3' folder and try again.

python readline module giving PermissionError: [Errno 1] only when run at startup

I'm making a console based game that saves input history, to help with debugging I created a function that will automatically input commands on start
def __readfile (self) -> None:
lines = None
with open("insts.txt", "r") as f:
lines = f.read().split("\n")
if (lines == None):
print("attempted to read insts.txt for instructions, could not find file")
return
self.__initfile = True
for line in lines:
self.parse_input(line)
self.__initfile = False
in the instance of the error "self.parse_input" ultimately leads to "readline.read_history_file" and none of the code in between the two has any effect on the error
but it gives this error message:
Traceback (most recent call last):
File "main.py", line 9, in <module>
game.start()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1353, in start
self.__readfile()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1345, in __readfile
self.parse_input(line)
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1223, in parse_input
self._parse_dialog(text)
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1128, in _parse_dialog
self._parse_dialog("leave")
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1101, in _parse_dialog
self._load_hist_scope()
File "/Users/tristans/Documents/GitHub/console-rpg/classes.py", line 1331, in _load_hist_scope
readline.read_history_file("history.txt")
PermissionError: [Errno 1] Operation not permitted
I have looked everywhere for an answer to where this error is coming from and can't find one
I've tried changing the file read operation from the "with open("insts.txt")" to a hardcoded list but that didn't work, os.access("history.txt", os.R_OK) also returns true when called just before "readline.read_history_file"
It appears to be a Mac-specific issue with readline. According to this answer, you need to use gnureadline on the Mac, rather than readline.
import gnureadline as readline

subprocess.Popen; FileNotFoundError :[WinError 2]. The system cannot find the file specified

I am working on a script to analysis proteins. One of the def if for creating a makeblastdb, and then use it to carry out blast. The code is as below:
import subprocess
from Bio import SeqIO
from Bio.Blast.Applications import NcbiblastnCommandline
def blast_file(input_data_files, db_files, output):
input_data_files = opts.input_file + '/protein_extracted_file.fa'
db_files = opts.input_file +'/alleles_reference_db'
cmd = ["makeblastdb", "-in", db_files, "-dbtype", "prot", "-parse_seqids", "-out", output + "/temporary_db",
"-title", "temporary_db"]
my_file = subprocess.Popen(cmd)
my_file.wait()
blasttn_cline = NcbiblastnCommandline(query=input_data_files, subject=db_files, evalue=0.001, outfmt=5,
out=output + '/blast_output.xml')
blasttn_cline()
The script works well until it get to the above def, and I get the error message:
Traceback (most recent call last):
**> File "open.py", line 234, in <module>
> main() File "open.py", line 229, in main
> blast_file(input_data_files, db_files, output) File "open.py", line 165, in blast_file
> my_file = subprocess.Popen(cmd)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
> restore_signals, start_new_session) File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in
> _execute_child
> startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified**
How can I make this to work for python3? Originally the script was written in python2.7, and I have updated most of it but I am stuck in this area. Any suggestion to update it?

IO Error python PIL image preprocessing script

I am following this tutorial and specifically going through the "generate own data" section:
https://github.com/surfertas/deep_learning/tree/master/projects/imdbwiki-challenge
https://github.com/surfertas/deep_learning/blob/master/projects/imdbwiki-challenge/imdb_preprocess.py
and i am facing this issue running the imdb_preprocess.py script;
Dictionary created...
Converting 1000 samples. (0=all samples)
Traceback (most recent call last):
File "imdb_preprocess.py", line 137, in <module>
main()
File "imdb_preprocess.py", line 131, in main
create_and_dump(imdb_dict, args.partial)
File "imdb_preprocess.py", line 106, in create_and_dump
for img_path in imgs
File "/usr/lib64/python2.7/site-packages/scipy/misc/pilutil.py", line 156, in imread
im = Image.open(name)
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2477, in open
fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: u'/path/48/10000548_1925-04-04_1964.jpg'
Now i manually checked folder 48 and checked that the image is complaining about is indeed there.
Any hints on where the fault is?
path was replaced

Categories

Resources