且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

由 py2exe 和 pyinstaller 生成的 exe 不起作用

更新时间:2023-12-01 23:07:58

解决了!

以下是screenshot.py 的修改后的代码.通过 py2exe 运行它.

Below are the modified code for screenshot.py. Run it via py2exe.

from multiprocessing import Process, freeze_support
from PIL import Image
import pyscreenshot as ImageGrab
import time

time.sleep(3)


save_dir = "C:/Users/ling/Downloads/test/"

def grab():
    im = ImageGrab.grab()
    im.save(save_dir + "screenshot.png")

if __name__ == "__main__":
    freeze_support()
    p = Process(target=grab)
    p.start()

事实证明,我需要从 multiprocessing 中包含 freeze_supportProcess

It turned out that I need to include freeze_support and Process from multiprocessing