скомпилилось с pyinstaller на win7
This commit is contained in:
+89
-97
@@ -1,119 +1,111 @@
|
||||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
import PySide6
|
||||
|
||||
USE_NUITKA = True # переключатель: True — сборка через Nuitka, False — через PyInstaller
|
||||
|
||||
pyside6_path = os.path.dirname(PySide6.__file__)
|
||||
plugins_platforms_path = os.path.join(pyside6_path, "plugins", "platforms")
|
||||
|
||||
dist_path = os.path.abspath(".") # итоговая папка с exe
|
||||
work_path = os.path.abspath("./build_temp") # временная папка для PyInstaller
|
||||
spec_path = os.path.abspath("./build_temp") # папка exдля spec-файлов PyInstaller
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
libclang_path = os.path.join(script_dir, "libclang.dll")
|
||||
libssl_orig = os.path.join(script_dir, "libssl-3-x64.dll")
|
||||
libcrypto_orig = os.path.join(script_dir, "libcrypto-3-x64.dll")
|
||||
|
||||
# Собираем бинарники и данные для PyInstaller
|
||||
add_binary_list = [f"{libclang_path};."]
|
||||
|
||||
if os.path.exists(libssl_orig):
|
||||
add_binary_list.append(f"{libssl_orig};libssl.dll")
|
||||
else:
|
||||
print("WARNING: libssl-3-x64.dll не найден, OpenSSL не будет включён")
|
||||
|
||||
if os.path.exists(libcrypto_orig):
|
||||
add_binary_list.append(f"{libcrypto_orig};libcrypto.dll")
|
||||
else:
|
||||
print("WARNING: libcrypto-3-x64.dll не найден, OpenSSL не будет включён")
|
||||
|
||||
from pathlib import Path
|
||||
from PIL import Image # нужна библиотека Pillow для конвертации PNG в ICO
|
||||
import PySide2
|
||||
from PyInstaller.utils.hooks import collect_data_files
|
||||
|
||||
# === Конфигурация ===
|
||||
USE_NUITKA = True # True — сборка через Nuitka, False — через PyInstaller
|
||||
SCRIPT_PATH = Path("./Src/DebugVarEdit_GUI.py")
|
||||
OUTPUT_NAME = "DebugVarEdit"
|
||||
|
||||
DIST_PATH = Path("./").resolve()
|
||||
WORK_PATH = Path("./build_temp").resolve()
|
||||
SPEC_PATH = WORK_PATH
|
||||
SCRIPT_DIR = Path(__file__).resolve().parent
|
||||
ICON_PATH = SCRIPT_DIR / "icon.png"
|
||||
ICON_ICO_PATH = SCRIPT_DIR / "icon.ico"
|
||||
|
||||
# === Пути к DLL и прочим зависимостям ===
|
||||
LIBS = {
|
||||
"libclang.dll": SCRIPT_DIR / "libclang.dll",
|
||||
"libssl.dll": SCRIPT_DIR / "libssl-3-x64.dll",
|
||||
"libcrypto.dll": SCRIPT_DIR / "libcrypto-3-x64.dll"
|
||||
}
|
||||
|
||||
# === PySide2 плагины ===
|
||||
PySide2_path = Path(PySide2.__file__).parent
|
||||
datas = []
|
||||
datas += collect_data_files('PySide6', includes=['plugins/platforms/*'])
|
||||
datas += collect_data_files('PySide6', includes=['plugins/styles/*'])
|
||||
datas += collect_data_files('PySide6', includes=['plugins/imageformats/*'])
|
||||
datas += collect_data_files('PySide2', includes=['plugins/platforms/*'])
|
||||
datas += collect_data_files('PySide2', includes=['plugins/styles/*'])
|
||||
datas += collect_data_files('PySide2', includes=['plugins/imageformats/*'])
|
||||
|
||||
add_data_list = [f"{src};{dest}" for src, dest in datas]
|
||||
add_binary_list = [f"{str(LIBS['libclang.dll'])};."]
|
||||
|
||||
script_path = "./Src/setupVars_GUI.py"
|
||||
output_name = "DebugVarEdit"
|
||||
# Проверка наличия DLL и добавление
|
||||
for name, path in LIBS.items():
|
||||
if path.exists():
|
||||
if name != "libclang.dll":
|
||||
add_binary_list.append(f"{str(path)};{name}")
|
||||
else:
|
||||
print(f"WARNING: {path.name} не найден — он не будет включён в сборку")
|
||||
|
||||
# === Сборка ===
|
||||
env = os.environ.copy()
|
||||
env["CC"] = r"C:\Users\I\AppData\Local\Nuitka\Nuitka\Cache\DOWNLOADS\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\bin\gcc.exe"
|
||||
env["CXX"] = r"C:\Users\I\AppData\Local\Nuitka\Nuitka\Cache\DOWNLOADS\gcc\x86_64\14.2.0posix-19.1.1-12.0.0-msvcrt-r2\bin\g++.exe"
|
||||
|
||||
if not USE_NUITKA:
|
||||
# PyInstaller команда
|
||||
cmd = [
|
||||
"pyinstaller",
|
||||
"--onefile",
|
||||
"--name", output_name,
|
||||
*[item for add_bin in add_binary_list for item in ("--add-binary", add_bin)],
|
||||
*[item for add_dat in add_data_list for item in ("--add-data", add_dat)],
|
||||
"--distpath", dist_path,
|
||||
"--workpath", work_path,
|
||||
"--specpath", spec_path,
|
||||
"--hidden-import", "PySide6.QtWidgets",
|
||||
"--hidden-import", "PySide6.QtGui",
|
||||
"--hidden-import", "PySide6.QtCore",
|
||||
"--windowed",
|
||||
script_path
|
||||
]
|
||||
else:
|
||||
# Nuitka команда
|
||||
# Конвертация PNG в ICO, если ICO нет или PNG новее ICO
|
||||
if ICON_PATH.exists():
|
||||
if (not ICON_ICO_PATH.exists()) or (ICON_PATH.stat().st_mtime > ICON_ICO_PATH.stat().st_mtime):
|
||||
img = Image.open(ICON_PATH)
|
||||
img.save(ICON_ICO_PATH, format='ICO', sizes=[(256,256), (128,128), (64,64), (32,32), (16,16)])
|
||||
|
||||
# Удалим временные папки до сборки
|
||||
def clean_temp():
|
||||
for folder in ["build_temp", "__pycache__", "DebugVarEdit_GUI.build", "DebugVarEdit_GUI.dist", "DebugVarEdit_GUI.onefile-build"]:
|
||||
path = Path(folder)
|
||||
if path.exists():
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
|
||||
# Формируем --include-data-dir для плагинов PySide6 (datas как в PyInstaller)
|
||||
# Было — неправильный способ: передаёт файлы
|
||||
plugin_dirs = set()
|
||||
for src, dest in datas:
|
||||
src_dir = os.path.dirname(src)
|
||||
dest_root = dest.split("/", 1)[0] if "/" in dest else dest
|
||||
plugin_dirs.add((src_dir, dest_root))
|
||||
|
||||
include_data_dirs = [
|
||||
f"--include-data-dir={src}={dest}" for src, dest in plugin_dirs
|
||||
]
|
||||
|
||||
include_data_files = []
|
||||
for dll_path, dll_name in [(libclang_path, "libclang.dll"),
|
||||
(libssl_orig, "libssl.dll"),
|
||||
(libcrypto_orig, "libcrypto.dll")]:
|
||||
if os.path.exists(dll_path):
|
||||
include_data_files.append(f"--include-data-file={dll_path}={dll_name}")
|
||||
|
||||
if USE_NUITKA:
|
||||
# Формируем include-data-file только для DLL
|
||||
include_data_files = [f"--include-data-file={str(path)}={name}" for name, path in LIBS.items() if path.exists()]
|
||||
|
||||
cmd = [
|
||||
"python", "-m", "nuitka",
|
||||
"--standalone", # полностью независимый билд (аналог PyInstaller --onefile/--onedir)
|
||||
"--onefile", # упаковать в один exe (экспериментально)
|
||||
"--enable-plugin=pyside6",
|
||||
"--windows-console-mode=disable",
|
||||
f"--output-dir={dist_path}",
|
||||
f"--output-filename={output_name}.exe",
|
||||
] + include_data_dirs + [
|
||||
script_path
|
||||
"--standalone",
|
||||
"--debug",
|
||||
"--debugger",
|
||||
"--mingw64",
|
||||
"--enable-plugin=pyside2",
|
||||
f"--output-dir={DIST_PATH}",
|
||||
f"--output-filename={OUTPUT_NAME}.exe",
|
||||
f"--windows-icon-from-ico={ICON_ICO_PATH}",
|
||||
*include_data_files,
|
||||
str(SCRIPT_PATH)
|
||||
]
|
||||
else:
|
||||
# PyInstaller
|
||||
cmd = [
|
||||
"pyinstaller",
|
||||
"--name", OUTPUT_NAME,
|
||||
"--distpath", str(DIST_PATH),
|
||||
"--workpath", str(WORK_PATH),
|
||||
"--specpath", str(SPEC_PATH),
|
||||
"--windowed",
|
||||
f"--icon={ICON_ICO_PATH}",
|
||||
"--hidden-import=PySide2.QtWidgets",
|
||||
"--hidden-import=PySide2.QtGui",
|
||||
"--hidden-import=PySide2.QtCore",
|
||||
*[arg for b in add_binary_list for arg in ("--add-binary", b)],
|
||||
*[arg for d in add_data_list for arg in ("--add-data", d)],
|
||||
str(SCRIPT_PATH)
|
||||
]
|
||||
|
||||
# Удаляем временные папки, если они у тебя есть
|
||||
temp_dirs = ["build_temp", "__pycache__"] # добавь свои папки с временными файлами
|
||||
for d in temp_dirs:
|
||||
if os.path.exists(d):
|
||||
shutil.rmtree(d)
|
||||
|
||||
print("Выполняется сборка:")
|
||||
# === Запуск сборки ===
|
||||
print("Выполняется сборка с помощью " + ("Nuitka" if USE_NUITKA else "PyInstaller"))
|
||||
print(" ".join(cmd))
|
||||
|
||||
result = subprocess.run(cmd, env=env)
|
||||
try:
|
||||
subprocess.run(cmd, check=True, env=env)
|
||||
print("\nСборка успешно завершена!")
|
||||
|
||||
if result.returncode == 0:
|
||||
# Чистим временные папки, только для PyInstaller (для Nuitka обычно не нужно)
|
||||
if not USE_NUITKA:
|
||||
for folder in ["build_temp", "__pycache__"]:
|
||||
if os.path.exists(folder):
|
||||
shutil.rmtree(folder)
|
||||
print("Сборка успешно завершена!")
|
||||
else:
|
||||
print("Сборка завершилась с ошибкой.")
|
||||
# Удаление временных папок после сборки
|
||||
#clean_temp()
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
print("\nОшибка при сборке.")
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['..\\generateVars.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
[],
|
||||
name='generateVars',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Binary file not shown.
Binary file not shown.
@@ -1,38 +0,0 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['..\\scanVars.py'],
|
||||
pathex=[],
|
||||
binaries=[('F:\\Work\\Projects\\TMS\\TMS_new_bus\\Src\\DebugTools/build/libclang.dll', '.')],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
[],
|
||||
name='scanVars',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
Reference in New Issue
Block a user