How to solve subprocess.run() execution error? - python

this is my code:
import subprocess
completed = subprocess.run(['ls', '-1'])
print('returncode:', completed.returncode)
this is the error i am getting:
Traceback (most recent call last):
File "getDataFromOpenImages_snowman.py", line 3, in <module>
completed = subprocess.run(['ls', '-1'])
File "C:\Users\pavan\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\pavan\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\pavan\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Question: what is the problem with my code?

Related

OSError in willson davidson programme

I am runnning the python script pywd2015.py. Everything goes fine till i create a light curve. I get the following error.
qt.xkb.compose: failed to create compose table Traceback (most recent call last): File "/home/anil/astronomylab/Wilsion devinay /src/interfaces/syntheticcurve_interface.py", line 288, in plot_selected_light_curve results = lc_io.fill_for_synthetic_light_curve().save().run().read_synthetic_light_curve() File "/home/anil/astronomylab/Wilsion devinay /src/helpers/wd_utils/wd_io.py", line 44, in run self.process = subprocess.Popen(cmd, cwd=self._cwd) File "/usr/lib/python3.10/subprocess.py", line 969, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) OSError: [Errno 8] Exec format error: '/home/anil/astronomylab/Wilsion devinay /wd-precompiled/lc_source.obj
I have tried to find the solution on internet, but i am unable to get any solution. Plese help to resolve the problem! What is causing it?

Error while running bash command in python using subprocess: [WinError 2] The system cannot find the file specified

I am trying to execute the following bash command in python using the subprocess python package but its throwing me an error.
the bashCommand variable in the following code stores the bash command i'm trying to execute
def desc_calc():
bashCommand = "java -Xms2G -Xmx2G -Djava.awt.headless=true -jar ./PaDEL-Descriptor/PaDEL-Descriptor.jar -removesalt -standardizenitro -fingerprints -descriptortypes ./PaDEL-Descriptor/PubchemFingerprinter.xml -dir ./ -file descriptors_output.csv"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
upon running the code, i get the following error:
2023-01-25 17:27:06.101 Uncaught app exception
Traceback (most recent call last):
File "C:\Users\oo_wa\.conda\envs\streamlit\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 563, in _run_script
exec(code, module.__dict__)
File "C:\Users\oo_wa\OneDrive\Desktop\BUSI_Dashboard\pages\2_Drug Discovery.py", line 82, in <module>
desc_calc()
File "C:\Users\oo_wa\OneDrive\Desktop\BUSI_Dashboard\pages\2_Drug Discovery.py", line 44, in desc_calc
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
File "C:\Users\oo_wa\.conda\envs\streamlit\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\oo_wa\.conda\envs\streamlit\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

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

I am trying to open a shortcut for Notepad called Notepad.lnk.
Because I want to learn how to open applications so I can use the pygui library to manipulate them.
Got FileNotFoundError
I got this error:
Traceback (most recent call last):
File "C:\Users\{my_name}\PycharmProjects\texture-gen\main.py", line 185, in <module>
subprocess.run(['start', shortcut_path], check=True)
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Code
This is my python code:
if __name__ == '__main__':
import os
import subprocess
cwd = os.getcwd()
shortcut_path = os.path.join(cwd, 'Notepad.lnk')
if not os.path.exists(shortcut_path):
print('Error: "Notepad.lnk" shortcut not found')
subprocess.run(['start', shortcut_path], check=True)
Debugging
I have checked the name of the shortcut is Notepad.lnk and is in the current working directory.
Why is this not working?

I keep getting PermissionError: [WinError 5] Access is denied on Pytesserect

I know this has been answered but nothing works, I run my code
import pytesseract
import cv2
pytesseract.pytesseract.tesseract_cmd = r"C:\\Users\\aidan\\AppData\\Local\\Tesseract-OCR"
image = cv2.imread(r'C:\Users\aidan\OneDrive\Desktop\download.jpg')
cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
print(pytesseract.image_to_string(image))
cv2.imshow('Result',image)
cv2.waitKey()
and I always get this error
[ WARN:0#0.043] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('download.jpg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
how can I fix this?
You have dropped the executable in the cmd-variable:
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\aidan\AppData\Local\Tesseract-OCR\tesseract.exe"

Python subprocess.Popen, .run, or .call would not work on bootsect.exe

I tried invoking bootsect.exe with subprocess.Popen, subprocess.run, subprocess.call, or even os.system but I keep getting the error below...
File "<stdin>", line 1, in <module>
File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\username\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\username\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
For instance, I get this error if use the code below...
import subprocess
subprocess.Popen('bootsect')
I can run diskpart or cmd using Popen but not bootsect for some reason. Any thoughts?

Categories

Resources