[英]Python Tkinter with Pyscreenshot script doesn't run after compiling with Pyinstaller
[英]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.