繁体   English   中英

使用 PyInstaller 编译为 exe 后,作为 ImageGrab 的 pyscreenshot 不起作用

[英]pyscreenshot as ImageGrab doesn't work after compiling with PyInstaller to exe

当我在编译之前正常使用代码时,它工作得很好,但是当使用 cxfreeze 或 pyinstaller 编译 to.exe 并运行软件时冻结

import pyscreenshot as ImageGrab
import threading

def wprint():
    print("Wprint")
    global tempimg
    imagem = ImageGrab.grab()
    tempimg = imagem
    print("End Wprint")


x = threading.Thread(target=wprint)
x.start()

如果我们打开日志记录,我们可以看到该模块通过生成一个进程来运行 PIL 来工作

DEBUG:pyscreenshot.loader:running "pil" in child process
DEBUG:easyprocess:command: ['C:\\Users\\user\\.virtualenvs\\random\\Scripts\\python.exe', '-m', 'pyscreenshot.cli.grab', '--filename', 'C:\\Users\\user\\AppData\\Local\\Temp\\pyscreenshotbza0zwqm\\screenshot.png', '--backend', 'pil', '--debug']
DEBUG:easyprocess:process was started (pid=29996)
Wprint
DEBUG:easyprocess:process has ended, return code=0
DEBUG:easyprocess:stdout=
DEBUG:easyprocess:stderr=
DEBUG:PIL.PngImagePlugin:STREAM b'IHDR' 16 13
DEBUG:PIL.PngImagePlugin:STREAM b'IDAT' 41 65536
End Wprint

当您 package 您的应用程序时,它会尝试针对您生成的 exe 作为解释器(上面的第一个参数)运行新进程,但是您的脚本不处理 arguments 中的任何内容,因此它刚刚重新启动,这又产生了另一个过程,这将重复,直到您的资源耗尽或直到您终止它。

pyscreenshot package 的 pypi 主页提到它已经过时了,因为 PIL(枕头)现在可以正确处理它最初试图解决的问题,而且在您的平台上似乎没有必要。 所以你也可以直接试试pillow的ImageGrab,应该有正常的Python API。

在大多数情况下,pyscreenshot 模块已过时。 创建它是因为 PIL ImageGrab 模块仅适用于 Windows,但现在也支持 Linux 和 macOS。 pyscreenshot 中有一些功能在特殊情况下很有用:灵活的后端、Wayland 支持、有时更好的性能、可选的子处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM