有没有办法通过窗口化的 PyInstaller 获取进程列表?
Is there a way to get a list of processus with PyInstaller windowed?
我正在尝试测试浏览器是否在 python 程序上打开并转换为 exe
和 pyinstaller
,有没有一种方法可以在不显示 window 并将其转换为 exe
?
我尝试了子进程,但它在 pyinstaller 的 windowed 模式下产生了错误,我无法将 psutil
导入 pyinstaller ("can't import psutil" error)
我与 subprocess
一起使用的代码:
enter code here
subprocess.check_output('tasklist', shell=真)
程序没有启动,出现错误信息:"Failed to execute script"
此处发布了类似的错误:
提前感谢您的回答
如果您只想检查一个进程是否 运行 您可以使用 psutil.process_iter
but as Pyinstaller can't quite resolve the psutil
module you need to use add-data
标志将整个 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
我正在尝试测试浏览器是否在 python 程序上打开并转换为 exe
和 pyinstaller
,有没有一种方法可以在不显示 window 并将其转换为 exe
?
我尝试了子进程,但它在 pyinstaller 的 windowed 模式下产生了错误,我无法将 psutil
导入 pyinstaller ("can't import psutil" error)
我与 subprocess
一起使用的代码:
enter code here
subprocess.check_output('tasklist', shell=真)
程序没有启动,出现错误信息:"Failed to execute script"
此处发布了类似的错误:
提前感谢您的回答
如果您只想检查一个进程是否 运行 您可以使用 psutil.process_iter
but as Pyinstaller can't quite resolve the psutil
module you need to use add-data
标志将整个 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