OSError: [WinError 740] The requested operation requires elevation - python

I am having a simple code which has an image called "try.png" and I want to convert it from Image to Text using pytesseract but I am having some issues with the code.
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'
img = cv2.imread('try.png')
img= cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(img))
But it's giving me an error.
Traceback (most recent call last):
File "C:/Users/user 1/PycharmProjects/JARVIS/try.py", line 6, in <module>
print(pytesseract.image_to_string(img))
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 356, in image_to_string
return {
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 359, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 270, in run_and_get_output
run_tesseract(**kwargs)
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 241, in run_tesseract
raise e
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pytesseract\pytesseract.py", line 238, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user 1\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 740] The requested operation requires elevation
Process finished with exit code 1
Any idea on how to over come this error

tesseract-ocr-setup-4.00.00dev.exe sounds like a setup exe and not the tesseract itself. Check if you have actually installed tesseract and if not launch the exe to install.
For Windows download the latest version from here:
https://github.com/UB-Mannheim/tesseract/wiki
If you still get OSError: [WinError 740] The requested operation requires elevation try changing the tesseract executable to run as admin: Right Click tesseract.exe -> Properties -> Compability -> Check Run this program as an administrator -> OK .

I guess you have not installed tesseract on your system. Run tesseract-ocr-setup-4.00.00dev.exe to install it and make a note of the location where it is installed ($tesseractLocation)
If getting the same error while installing, try running it with admin access.
And Replace
pytesseract.pytesseract.tesseract_cmd=r'tesseract-ocr-setup-4.00.00dev.exe'
with
pytesseract.pytesseract.tesseract_cmd=r'$tesseractLocation'
This will resolve the issue. In the script, you have to mention the installation directory and not the setup file.

Try Uncheck "Run this program as an administrator"
TRY: Right Click tesseract.exe -> Properties -> Compability -> Uncheck Run this program as an administrator -> apply.

Related

Getting error when trying to use Winotify (Python)

I'm trying to use the python module Winotify
to create toast notifications, but I'm running into a problem that I can't make heads or tails out off.
The test script I'm trying to run is the following:
from winotify import Notification
toast = Notification(app_id="windows app",
title="Winotify Test Toast",
msg="New Notification!")
toast.show()
But get the following error
Traceback (most recent call last):
File "D:\01 Libraries\Documents\Tosh0kan Studios\Coding\MangaDex Feed Notifier\_toaster.pyw", line 8, in <module>
toast.show()
File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\winotify\__init__.py", line 197, in show
_run_ps(command=self.script)
File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\site-packages\winotify\__init__.py", line 72, in _run_ps
subprocess.Popen(
File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1022, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\igor\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1491, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
I really have no clue what's going on, so the most I tried was uninstalling and reinstalling, installing it in an older version of Python I have (version 3.9), and it still has the same problem.
Does anyone have any idea of what's happening?
EDIT
As #Pignotto said below, Powershell wasn't on my PATH variable. Once I added it, it worked fine.

Having issue with running python script having pytesseract library from maven project

I wanted to run a python script from my Java Maven project. Simple python scripts works fine without any issues.
But if i try something complicated like using OpenCV and pytesseract libraries to do some image recognition related tasks the code doesn't work.
The python script works fine if i just run it from the terminal (i have installed all the required libraries)
But the same script when called from the Java Maven project, it doesn't work.
Here is the code:
String path = "/Users/team/Desktop/my.py";
ProcessBuilder pb = new ProcessBuilder("python3","/Users/team/Desktop/my.py").inheritIO();
Process p = pb.start();
p.waitFor();
BufferedReader bfr = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = bfr.readLine()) != null) {
System.out.println(line);
}
It is throwing below error:
Traceback (most recent call last):
File "/Users/team/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 252, in run_tesseract
proc = subprocess.Popen(cmd_args, **subprocess_args())
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/team/Desktop/my.py", line 73, in <module>
result = pytesseract.image_to_string(Image.open(src_path + "thres.png"))
File "/Users/team/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 413, in image_to_string
return {
File "/Users/team/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 416, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/Users/team/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 284, in run_and_get_output
run_tesseract(**kwargs)
File "/Users/team/Library/Python/3.8/lib/python/site-packages/pytesseract/pytesseract.py", line 256, in run_tesseract
raise TesseractNotFoundError()
Could someone please help me figure this out please? I feel like the issue is because of some sort of PATH, but not sure how to fix it!
Would you mind trying using -Djava.library.path= so the java process knows where to locate the tesseract library.

how to resolve error FileNotFoundError: [WinError 2] The system cannot find the file specified when using ffmpeg-python?

I'm trying to merge video and audio files together using ffmprg but I keep on receiving this error
ERROR:
Traceback (most recent call last):
File "C:\Users\Geo\youtubedownloader\test.py", line 9, in <module>
ffmpeg.concat(video,audio, v=1 , a=1).output("C:/Users/Geo/output_video/mergedretweett.mp4/").run()
File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 313, in run
process = run_async(
File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\site-packages\ffmpeg\_run.py", line 284, in run_async
return subprocess.Popen(
File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Geo\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Code:
video = ffmpeg.input("C:/Users/Geo/File.mp4")
audio = ffmpeg.input("C:/Users/Geo/File_audio.mp4")
ffmpeg.concat(video,audio, v=1 , a=1).output("C:/Users/Geo/output_video/outputvideo.mp4").run()```
The WindowsError you see does not refer to the video file but to the ffmpeg executable itself. The call to subprocess.call has no idea that File.mp4 is a filename you are passing. Windows knows that the first parameter ought to be an executable file and reports back to the interpreter that it can't find it.
Double-check that ffmpeg can be executed in the environment your interpreter is running in. You may either add it to your PATH or specify the full path to ffmpeg.exe.
I was also getting the same error.
Then I checked and found that, ffmpeg is needed.
When I installed it from this code:
conda install -c conda-forge ffmpeg
(for anaconda), my issue gets resolved.

Cannot import jsonstreamer / cannot pip install yajl-py

I'm trying to use JSON streamer to parse a large 11gb JSON file. JSONstreamer appears to be the only package that streams the file without having to load the entire file into memory first.
When I try to import jsonstreamer in python I get this error.
OSError: Yajl cannot be found.
When I try to pip install yajl I get this error:
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
However all there files are there
I downloaded the yajl.dll file from their webpage and added it into my C:\Windows\SysWOW64 dir.
Don't really have any ideas how to proceed because it seems like I am stuck.
I had the same problem, it's fixed installing git on the machine: there is a dependency for it in pip3 scripts.
The key was on the log, you can see how a git subprocess is executed:
Running setup.py (path:/tmp/pip-build-01hs0gev/yajl/setup.py) egg_info for package yajl
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip-build-01hs0gev/yajl/setup.py", line 64, in <module>
subprocess.call(['git', 'submodule', 'update',])
File "/usr/lib/python3.4/subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'git'

Error message when I try adblocker build

I am trying to build adblockplus from this link. When I issue the command:
python build.py build
I end up getting the following error message. I tried with and without sudo to no avail.
Traceback (most recent call last):
File "build.py", line 10, in <module>
buildtools.build.processArgs('.', sys.argv)
File "/home/machine/projects/weird/buildtools/build.py", line 352, in processArgs
commands[command](baseDir, scriptName, opts, args, type)
File "/home/machine/projects/weird/buildtools/build.py", line 39, in __call__
return self._handler(baseDir, scriptName, opts, args, type)
File "/home/machine/projects/weird/buildtools/build.py", line 166, in runBuild
limitMetadata=limitMetadata)
File "/home/machine/projects/weird/buildtools/packager.py", line 274, in createBuild
buildNum = getBuildNum(baseDir)
File "/home/machine/projects/weird/buildtools/packager.py", line 80, in getBuildNum
(result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIPE).communicate()
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Am I missing a package? Any hint on what the problem could be will be much appreciated.
The stack trace makes it clear that the issue is caused by the following line:
(result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIPE).communicate()
If you look at the subprocess package documentation, this line is trying to run the hg id -n command (get numerical Mercurial revision). Apparently, the Mercurial command line tool isn't present on your system (a possibility that this build script didn't consider) so it fails.
Disclaimer: I happen to be the one who wrote this script and I fixed this bug now. Mercurial isn't essential for the build, the revision number is pretty much only necessary to determine the output file name.

Categories

Resources