python - 操作系统错误 : [WinError 193] %1 is not a valid Win32 application

标签 python subprocess python-3.4

我正在尝试使用子进程从 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 脚本”吗?

最佳答案

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

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

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

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

关于python - 操作系统错误 : [WinError 193] %1 is not a valid Win32 application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25651990/

相关文章:

Python 3.4.3 - 如何使 textwrap 与 itertools 一起使用

python - 想想 Python - 无法让 tkinter 工作

python - 并行文档转换 ODT > PDF Libreoffice

python - gpg --passphrase-fd 不适用于 python 3 子进程

Python 3 : Capture return of `\x1b[6n` (`\033[6n` , `\e[6n` ) ansi 序列

python - 如何从 `stdin` 创建非阻塞连续读取?

python - 接收 SIGUSR2/SIGINT 时如何在 python 中获取子进程的标准输出

python - 皮威 ORM : select function()

python - 带 AnchoredText 的粗体文本(Python 和 Matplotlib)

python - 将图像传输到属于 pygame 网格一部分的图 block 上