无法使用python在exe文件中运行pyscreenshot代码

问题描述 投票:0回答:1

我想创建一个exe文件,该文件带有窗口屏幕截图。我为此创建了一个python脚本。如果我单独执行该脚本,则效果很好。但是,当我绑定此脚本并创建exe文件时,该脚本的代码不起作用。代码在下面给出...

screenshoter.py:

import pyscreenshot

def takeShot():
    im = pyscreenshot.grab()
    im.save('C:/screenshot_now1.png')

if __name__ == "__main__":
    print("Hey there")
    takeShot()

setup.py:

import sys
from cx_Freeze import setup, Executable

build_exe_options =  {"packages": ["pyscreenshot"]}
base = None
if sys.platform == "win32":
    base = "Console"

setup(name = "Screenshoter",
        version = "1.0",
        description = "Screenshot taker",
        options = {"build_exe": build_exe_options},
        executables = [Executable("screenshoter.py", base=base)]
    )

在CMD中:python setup.py bdist_msi

当我安装msi文件并运行exe文件时,我希望屏幕截图已被获取并存储在指定的路径中,但是它仅打印Hey there文本,但不进行任何屏幕截图。

[请帮助我解决此问题。谢谢。

python-3.x screenshot cx-freeze
1个回答
0
投票

我的代码也遇到同样的问题。当我手动运行程序时,此方法工作正常。但是当我使用pyinstaller在exe中转换程序时。它显示错误。下面给出的链接是我的问题在GitHub问题上的链接。

https://github.com/ponty/pyscreenshot/issues/74

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.