. Advertisement .
..3..
. Advertisement .
..4..
I get an error
import subprocess
subprocess.call(['hello.py', 'htmlfilename.htm'])
Traceback (most recent call last):
File "<pyshell#42>", line 1, in <module>
subprocess.call(['hello.py', 'htmlfilename.htm'])
File "C:\Python34\lib\subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application
when trying to call a Python file “hello.py” from within the python interpreter with subprocess. How to fix the oserror: [winerror 193] %1 is not a valid win32 application error? Please give me some advice.
It is quite obvious. The hello.py
file is not executable. The executable must be specified:
subprocess.call(['python.exe', 'hello.py', 'htmlfilename.htm'])
To make python.exe
visible in the search path, you can either pass the entire path to the executable that runs the calling script or the python.exe
address.
import sys
subprocess.call([sys.executable, 'hello.py', 'htmlfilename.htm'])
The cause: This error happens because the file
hello.py
is not an executable file. then you have to specify the executable:The solution: To resolve this error you’ll need
python.exe
to be in the search path, or you can specify the entire path to the executable file running the calling script:Installers of Python usually register.py files to the system. It works if you explicitly run the shell
On the command line, you can inspect your file associations.