OSError:[WinError 193]%1不是有效的Win32应用程序

发布于 2021-01-29 19:19:31

我试图从带有子进程的python解释器中调用python文件“ hello.py”。但我无法解决此错误。[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脚本”?提前致谢。

关注者
0
被浏览
429
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    错误非常明显。该文件hello.py不是可执行文件。您需要指定可执行文件:

    subprocess.call(['python.exe', 'hello.py', 'htmlfilename.htm'])
    

    您需要python.exe在搜索路径上可见,或者可以将完整路径传递给运行调用脚本的可执行文件:

    import sys
    subprocess.call([sys.executable, 'hello.py', 'htmlfilename.htm'])
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看