如何解决使用 PyInstaller 打包程序会破坏它
import pyautogui
import time
from threading import Thread
import os
import signal
from multiprocessing import Process
import keyboard
def clicker():
while True:
pyautogui.mouseDown(button="left")
time.sleep(0.05)
pyautogui.mouseUp(button="left")
time.sleep(3)
def exit_thrd():
global running
keyboard.wait("m")
string_ext = (f"if running:"
f"\n proces_{broj_procesa}.kill()"
f"\n proces_{broj_procesa}.join()"
f"\n proces_{broj_procesa}.close()"
)
exec(string_ext)
print("Exited!")
os.kill(os.getpid(),signal.SIGTERM)
if __name__ == "__main__":
ext_thrd = Thread(target=exit_thrd)
ext_thrd.start()
broj_procesa = 0
# instructions
print("Started!\nPress n to start-stop\nPress m to exit")
running = False
while True:
keyboard.wait("n")
if not running:
running = True
broj_procesa += 1
exec(f"proces_{broj_procesa} = Process(target=clicker)\nproces_{broj_procesa}.start()")
else:
running = False
exec(f"proces_{broj_procesa}.kill()\nproces_{broj_procesa}.join()")
我为 minecraft 制作了一个简单的自动点击器。当我启动它时,它等待我按 n 开始点击。如果我再次按 n 它会停止,然后我可以按 n 重新开始。当我按 m 它退出。当我从 PyCharm 运行它时它工作得很好,但是当我使用 PyInstaller 将它打包为可执行文件时,它会中断。我使用 PyInstaller 创建 EXE 的参数是:
pyinstaller "auto-click.py" --console --icon "click-bot.ico" --uac-admin --onefile --name "Click-Bot"
现在,当我运行 PyInstaller 创建的 EXE 时,它会打印出说明消息,但是当我单击 n 时,它会再次打印出来。每次我按 n 时一次又一次。当我按 m 它退出没有问题艰难。我知道我可能没有使这个程序成为可能的最佳方式,因为我知道 exec 的使用并不是真正可取的,但是我需要再次启动进程,因为当我启动和停止进程时,并尝试再次启动它,它弹出错误,所以这样我只是在制作新流程。随意更正我的程序,还有一些变量名称是克罗地亚语,但这并不重要。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。