OSError: [WinError 193] %1 不是有效的 Win32 应用程序 [英] OSError: [WinError 193] %1 is not a valid Win32 application
问题描述
我正在尝试从带有子进程的 python 解释器中调用 python 文件hello.py".但我无法解决此错误.[Python 3.4.1].
I am trying to call a python file "hello.py" from within the python interpreter with subprocess. But I am unable to resolve this error. [Python 3.4.1].
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
除了使用子进程之外,还有其他方法可以使用参数调用python脚本"吗?提前致谢.
Also is there any alternate way to "call a python script with arguments" other than using subprocess? Thanks in advance.
推荐答案
错误很明显.文件 hello.py
不是可执行文件.您需要指定可执行文件:
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'])
您需要 python.exe
在搜索路径上可见,或者您可以将完整路径传递给运行调用脚本的可执行文件:
You'll 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'])
这篇关于OSError: [WinError 193] %1 不是有效的 Win32 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!