-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_app.py
More file actions
67 lines (57 loc) · 2.42 KB
/
Copy pathbuild_app.py
File metadata and controls
67 lines (57 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import subprocess
import sys
import customtkinter
from pathlib import Path
def get_customtkinter_path():
"""customtkinter の場所を取得する。"""
return os.path.dirname(customtkinter.__file__)
def main():
print("--- Python App Launcher Universal Builder ---")
# 1. 必要なパスの準備
ctk_path = get_customtkinter_path()
assets_path = os.path.abspath("assets")
app_module_path = os.path.abspath("app")
# OS ごとの区切り文字 (Windows は ; , 他は :)
sep = ";" if os.name == "nt" else ":"
# 2. PyInstaller コマンドの構築
# 直接 'pyinstaller' を呼ぶとパスの問題が起きる場合があるため、python -m を使用
cmd = [
sys.executable, "-m", "PyInstaller",
"--noconsole", # コンソールウィンドウを表示しない
"--onefile", # 単一の実行ファイルにまとめる
f"--add-data={ctk_path}{sep}customtkinter", # CTK のアセットを含める
f"--add-data={assets_path}{sep}assets", # 自前のアセットを含める
f"--add-data={app_module_path}{sep}app", # app モジュールを含める
]
# OS 別のアイコン設定
if sys.platform == "win32":
icon_path = os.path.join(assets_path, "icon.ico")
if os.path.exists(icon_path):
cmd.append(f"--icon={icon_path}")
elif sys.platform == "darwin":
icon_path = os.path.join(assets_path, "icon.icns")
if os.path.exists(icon_path):
cmd.append(f"--icon={icon_path}")
cmd.append("--windowed") # Mac ではこれが必要
# 3. ターゲットの指定
cmd.extend([
"--name=PythonAppLauncher",
"main.py"
])
print(f"Executing: {' '.join(cmd)}")
try:
# PyInstaller を実行
subprocess.check_call(cmd)
print("\n--- Build Successful! ---")
print(f"The executable can be found in the 'dist' folder.")
except subprocess.CalledProcessError:
print("\n--- Build Failed! ---")
print("Make sure PyInstaller is installed: pip install pyinstaller")
sys.exit(1)
except FileNotFoundError:
print("\n--- Error: PyInstaller not found! ---")
print("Please install it using: pip install pyinstaller")
sys.exit(1)
if __name__ == "__main__":
main()