python – OSError: [WinError 193] %1 is not a valid Win32 application
python – OSError: [WinError 193] %1 is not a valid Win32 application
The error is pretty clear. The file hello.py
is not an executable file. You need to specify the executable:
subprocess.call([python.exe, hello.py, htmlfilename.htm])
Youll need python.exe
to be visible on the search path, or you could pass the full path to the executable file that is running the calling script:
import sys
subprocess.call([sys.executable, hello.py, htmlfilename.htm])
Python installers usually register .py files with the system. If you run the shell explicitly, it works:
import subprocess
subprocess.call([hello.py, htmlfilename.htm], shell=True)
# --- or ----
subprocess.call(hello.py htmlfilename.htm, shell=True)
You can check your file associations on the command line with
C:>assoc .py
.py=Python.File
C:>ftype Python.File
Python.File=C:Python27python.exe %1 %*
python – OSError: [WinError 193] %1 is not a valid Win32 application
I got the same error while I forgot to use shell=True
in the subprocess.call
.
subprocess.call(python modify_depth_images.py, shell=True)
To run an external command without interacting with it, such as one
would do withos.system()
, Use thecall()
function.import subprocess Simple command subprocess.call([ls, -1], shell=True)