简体   繁体   English

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

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

When I use the code normally before compiling it works perfectly but when compiling to.exe with cxfreeze or pyinstaller and running the software freezes当我在编译之前正常使用代码时,它工作得很好,但是当使用 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()

If we turn on logging, we can see that the module works by spawning a process to run PIL in如果我们打开日志记录,我们可以看到该模块通过生成一个进程来运行 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

When you package your application, it'll try to run the new process against your generated exe as the interpreter (the first argument above), but your script doesn't handle anything from the arguments so it's just started again, which spawn an another process, and this will repeat until your resources are exhausted or until you terminate it.当您 package 您的应用程序时,它会尝试针对您生成的 exe 作为解释器(上面的第一个参数)运行新进程,但是您的脚本不处理 arguments 中的任何内容,因此它刚刚重新启动,这又产生了另一个过程,这将重复,直到您的资源耗尽或直到您终止它。

The pypi home page of the pyscreenshot package mentions that it's mostly obsolete as PIL (pillow) now properly handles what it tried to initially solve, and it appears that it wasn't necessary on your platform. pyscreenshot package 的 pypi 主页提到它已经过时了,因为 PIL(枕头)现在可以正确处理它最初试图解决的问题,而且在您的平台上似乎没有必要。 So you can also give pillow's ImageGrab a try directly which should have a normal Python API.所以你也可以直接试试pillow的ImageGrab,应该有正常的Python API。

The pyscreenshot module is obsolete in most cases.在大多数情况下,pyscreenshot 模块已过时。 It was created because PIL ImageGrab module worked on Windows only, but now Linux and macOS are also supported.创建它是因为 PIL ImageGrab 模块仅适用于 Windows,但现在也支持 Linux 和 macOS。 There are some features in pyscreenshot which can be useful in special cases: flexible backends, Wayland support, sometimes better performance, optional subprocessing. pyscreenshot 中有一些功能在特殊情况下很有用:灵活的后端、Wayland 支持、有时更好的性能、可选的子处理。

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

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