<pyinstaller, Python, WSH> Pythonスクリプトから実行ファイル(exe)を作る。
Pythonスクリプトから実行ファイルexeを作る、変換する。
pyinstallerちゅうのでできるらしい。
試してみた。
インストールは、pipさんで。condaさんにはなかった。
例のCalculatorをwin32comで、制御するスクリプトを変換。
スクリプト。
#!/usr/bin/env python # -*- coding: utf-8 -*- import win32api as WScript import win32com.client if __name__ == '__main__': WshShell = win32com.client.Dispatch("WScript.Shell") WshShell.Run("calc") WScript.Sleep(100) WshShell.AppActivate("Calculator") WScript.Sleep(100) WshShell.SendKeys("1{+}", 0) WScript.Sleep(500) WshShell.SendKeys("2") WScript.Sleep(500) WshShell.SendKeys("~") WScript.Sleep(500) WshShell.SendKeys("*3") WScript.Sleep(500) WshShell.SendKeys("~") WScript.Sleep(2500)
で、変換。
>pyinstaller -F -w calc.py
で、なにやらいろいろ呪文が並ぶ。
で、calc\distというフォルダの下に、calc.exeを発見。
できたっぽい。
で、クリック。
が、、問題発生
止まらない、、、
どんどんcalc.exeプロセスが増殖して、やりたい放題。
暴走。。。
しょーが無しに、Windows強制シャットダウン。
あかんがや、、、まったく。。。
その後、sys.exit()を最後に付ければ、暴走しないことを確認。
sys.exit()は必須。
お世話になったところ。