0

我正在尝试测试浏览器是否在转换为exewith的 python 程序上打开pyinstaller,有没有办法在不显示窗口并将其转换为的情况下测试它exe

我尝试了子进程,但它在 pyinstaller 的窗口模式下产生错误,我无法psutil导入pyinstaller ("can't import psutil" error)

我使用的代码subprocess

enter code heresubprocess.check_output('tasklist', shell=True)

程序未启动并出现错误消息:“无法执行脚本”此处发布了类似的错误:子进程似乎在 pyinstaller exe 文件中不起作用

预先感谢您的回答

4

1 回答 1

0

如果您只想检查一个进程是否正在运行,您可以使用psutil.process_iter但由于 Pyinstaller 无法完全解析psutil模块,您需要使用add-dataflag 将整个 Lib 文件夹添加到输出可执行文件中:

import psutil
process_to_find = "chrome.exe"
process_list = [p.name() for p in list(psutil.process_iter())]
if process_to_find in process_list:
   # do whatever you want
   print("Process found!")

接下来使用以下命令生成可执行文件(您也可以使用-w标志):

pyinstaller -F --add-data "<python_path>\Lib\site-packages\psutil;./psutil" script.py 
于 2019-07-25T10:57:30.353 回答