I have a Raspberry PI and I want to automatically open a website at boot time.
So I made an auto start config to run a python (v.3.5.3) script on boot.
The python script looks like this:
import os
import subprocess
subprocess.call([/home/pi/Desktop/Shortcut Final.desktop])
But I get the error:
Traceback (most recent call last): File "/home/pi/myscript.py", line 3
subprocess.call([/home/pi/Desktop/Shortcut Final.desktop])
^ SyntaxError: invalid syntax
I got my instructions from a guide that used windows file location, so I think the error is that my file location dont start with a directory letter like C:, but I dont think raspbian use the same system.
I have not found any other guides that explain how to accomplish the same thing in simple terms (as i only know very basic python coding)
I have looked into the open() command, but it seemed complicated.
Any tips on how to accomplish my goal/solve the error?
After putting the file location in quotes the syntax error disappears and i encounter a new error:
Traceback (most recent call last):
File "/home/pi/myscript.py", line 5, in <module>
subprocess.call(["/home/pi/Desktop/Shortcut Final.desktop"])
File "/usr/lib/python3.5/subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1282, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
Related
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.
I am new to python scripting. I am trying to run subprocess methods on Python Idle and getting these errors:
import subprocess
subprocess.check_output("ls")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 336, in check_output
**kwargs).stdout
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\ramakrishna\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Please help me out to resolve this error.
Thank you
seems like you are running windows. Windows has no "ls" command, so you get a FileNotFoundError exception. I am not familiar with windows and python, but try "dir" instead of "ls", that should work.
I need to create a python script that runs a file gams (myfile.gms).
My file is in a folder F:\Otim\correct, so I was using a part of a code that I saw in this forum. I made:
import subprocess
subprocess.check_call(["F:\Otim\correct\myfile.gms"])
and I get an error:
Runtime error
Traceback (most recent call last):
File "<string>", line 80, in <module>
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 506, in check_call retcode = call(*popenargs, **kwargs)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 493, in call return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 679, in __init__errread, errwrite)
File "C:\Python27\ArcGIS10.2\Lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application
Can someone help me please? Thanks
I've never used gams but after a quick look at www.gams.com it sounds like myfile.gms is not the file to be executed but the input file to be given as argument to the gams executable.
So you should try something like :
import subprocess
subprocess.check_call([r"C:\path\to\programs\GAMS.exe",r"F:\Otim\correct\myfile.gms"])
Notice : there is a GAMS python API which could give you a more portable solution.
I am trying to run a nessus scan from cronjob by subprocess python module. ,but from cronjob it's is giving an error. But not giving any error on execution of script from bash?
the cronjob code
01 11 * * * /root/nessusscan.py
and subprocess call in script is
subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])
from bash it's working fine but from cronjob i am getting following error in mail
Traceback (most recent call last):
File "/root/nessusscan.py", line 9, in <module>
subprocess.call(['nessus','-q','-x','-T','nessus','127.0.0.1','1241','user','password','ip.txt','res'])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Thnx to evry one i am answering my own question for other people who will vist this thread. So that they can also get out of this error. In my case error got solved by giving the path of nessus which is "/opt/nessus/bin/nessus"
replaced nessus with "/opt/nessus/bin/nessus"
cronjob was not able to get the path of nessus command.It's working now.
I am working with WARC Tools, a python library for working with WARC files. I've installed everything and it all seems to work except for the last command. While I suspect many of you may not have worked with this tool, perhaps you can make sense of the error message for me.
When I run this command:
python /path/filesdump.py filtered.warc as per the documentation, I get this error message immediately:
html/811cac8c-7430-403b-96a4-7d77137b0d46.html
Traceback (most recent call last):
File "/users/ianmilligan1/desktop/warc/warc-tools-mandel/filesdump.py", line 63, in <module>
sys.exit(main(sys.argv))
File "/users/ianmilligan1/desktop/warc/warc-tools-mandel/filesdump.py", line 34, in main
dump_archive(fh,name)
File "/users/ianmilligan1/desktop/warc/warc-tools-mandel/filesdump.py", line 57, in dump_archive
txt = record.filedump(content=True)
File "/Users/ianmilligan1/Desktop/WARC/warc-tools-mandel/warctools/record.py", line 140, in filedump
p = Popen(['lynx', '-dump', '-stdin', '-nomargins', '-unique_urls', '-width=120'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1228, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
What's going on here? Where would you suggest I begin looking?
You need to install lynx, a command-line web browser that WARC Tools seems to require. That'll solve it.
What's going on is that warctools/record.py is calling lynx on line 140, and Python's subprocess library isn't finding the lynx executable so it throws an exception. They really ought to wrap the exception and provide a clearer message... Anyways. Try that and see if it fixes it.