Initial Pyinstaller Prep-Work

This commit is contained in:
Nicole Rappe 2025-04-17 02:37:10 -06:00
parent 0286b7b4b8
commit 2dc79a03ad
6 changed files with 97 additions and 10 deletions

5
.gitignore vendored
View File

@ -1,3 +1,6 @@
.vs/
/Server/
/Agent/
/Agent/
/Pyinstaller_Temp/
Borealis-Server.spec
/dist/

View File

@ -163,7 +163,7 @@ def run_screenshot_loop(node_id, cfg):
if node_id not in region_launchers:
launcher = RegionLauncher(node_id)
region_launchers[node_id] = launcher
launcher.trigger.emit(x, y, w, h)
QtCore.QTimer.singleShot(0, lambda: launcher.trigger.emit(x, y, w, h))
widget = overlay_widgets.get(node_id)
if widget:

View File

@ -2,6 +2,7 @@
import os
import io
import sys
import base64
import torch
import pytesseract
@ -13,16 +14,25 @@ from PIL import Image
# ---------------------------------------------------------------------
# Configure cross-platform Tesseract path
# ---------------------------------------------------------------------
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
SYSTEM = platform.system()
def get_tesseract_folder():
if getattr(sys, 'frozen', False):
# PyInstaller EXE
base_path = sys._MEIPASS
return os.path.join(base_path, "Borealis", "Python_API_Endpoints", "Tesseract-OCR")
else:
# Normal Python environment
base_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_dir, "Tesseract-OCR")
if SYSTEM == "Windows":
TESSERACT_FOLDER = os.path.join(BASE_DIR, "Tesseract-OCR")
TESSERACT_FOLDER = get_tesseract_folder()
TESSERACT_EXE = os.path.join(TESSERACT_FOLDER, "tesseract.exe")
TESSDATA_DIR = os.path.join(TESSERACT_FOLDER, "tessdata")
if not os.path.isfile(TESSERACT_EXE):
raise EnvironmentError("Missing tesseract.exe in /Tesseract-OCR. Ensure the full folder is copied.")
raise EnvironmentError(f"Missing tesseract.exe at expected path: {TESSERACT_EXE}")
pytesseract.pytesseract.tesseract_cmd = TESSERACT_EXE
os.environ["TESSDATA_PREFIX"] = TESSDATA_DIR

View File

@ -177,14 +177,14 @@ switch ($choice) {
Run-Step "Create Virtual Python Environment for Agent" {
# Create virtual environment for the agent
if (!(Test-Path "$venvFolder\Scripts\Activate")) {
python -m venv $venvFolder | Out-Null
python -m venv $venvFolder
}
# Copy the agent script if it exists
if (Test-Path $agentSourcePath) {
if (Test-Path $agentDestinationFolder) {
Remove-Item -Recurse -Force $agentDestinationFolder | Out-Null
Remove-Item -Recurse -Force $agentDestinationFolder
}
New-Item -Path $agentDestinationFolder -ItemType Directory -Force | Out-Null
New-Item -Path $agentDestinationFolder -ItemType Directory -Force
Copy-Item -Path $agentSourcePath -Destination $agentDestinationFile -Force
} else {
Write-Host "`r$($symbols.Info) Warning: Agent script not found at '$agentSourcePath', skipping copy." -ForegroundColor Yellow
@ -196,7 +196,7 @@ switch ($choice) {
# ---------------------- Agent: Install Python Dependencies ----------------------
Run-Step "Install Python Dependencies for Agent" {
if (Test-Path $agentRequirements) {
pip install -q -r $agentRequirements 2>&1 | Out-Null
pip install -q -r $agentRequirements 2>&1
} else {
Write-Host "`r$($symbols.Info) Agent-specific requirements.txt not found at '$agentRequirements', skipping Python packages." -ForegroundColor Yellow
}

View File

@ -0,0 +1,75 @@
#////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: <ProjectRoot>/Package-Borealis-Server.ps1
# ------------------- CONFIGURATION -------------------
$venvDir = "Pyinstaller_Virtual_Environment"
$serverScript = "Server\Borealis\server.py"
$outputName = "Borealis-Server"
$distExePath = "dist\$outputName.exe"
$buildDir = "Pyinstaller_Server_Build"
$specFile = "$outputName.spec"
$reactBuild = "Server\web-interface\build"
$tesseractDir = "Server\Borealis\Python_API_Endpoints\Tesseract-OCR"
# ------------------- ENV SETUP -------------------
Write-Host "`n[INFO] Preparing virtual environment and dependencies..." -ForegroundColor Cyan
$activateScript = "$venvDir\Scripts\Activate.ps1"
if (-Not (Test-Path $activateScript)) {
Write-Host "[SETUP] Creating virtual environment at $venvDir"
python -m venv $venvDir
}
# ------------------- ACTIVATE -------------------
Write-Host "[INFO] Activating virtual environment..."
. $activateScript
# ------------------- INSTALL DEPENDENCIES -------------------
Write-Host "[INFO] Installing project dependencies into virtual environment..."
pip install --upgrade pip > $null
pip install -r requirements.txt
# ------------------- INSTALL PYINSTALLER -------------------
Write-Host "[INFO] Installing PyInstaller..."
pip install pyinstaller > $null
# Resolve PyInstaller path
$pyInstallerPath = "$venvDir\Scripts\pyinstaller.exe"
if (-Not (Test-Path $pyInstallerPath)) {
Write-Host "[ERROR] PyInstaller not found even after install. Aborting." -ForegroundColor Red
exit 1
}
# ------------------- CLEANUP OLD BUILD -------------------
Write-Host "[INFO] Cleaning previous build artifacts..." -ForegroundColor Gray
Remove-Item -Recurse -Force "dist", "build", $specFile -ErrorAction SilentlyContinue
# ------------------- BUILD PYINSTALLER CMD -------------------
$reactStaticAssets = "$reactBuild;web-interface/build"
$tesseractAssets = "$tesseractDir;Borealis/Python_API_Endpoints/Tesseract-OCR"
$cmdArgs = @(
"--onefile",
"--noconfirm",
"--name", "$outputName",
"--add-data", "`"$reactStaticAssets`"",
"--add-data", "`"$tesseractAssets`"",
"--hidden-import=eventlet",
"--clean",
"`"$serverScript`""
)
$arguments = $cmdArgs -join " "
Write-Host "`n[INFO] Running PyInstaller with Start-Process..." -ForegroundColor Yellow
Start-Process -FilePath $pyInstallerPath -ArgumentList $arguments -Wait -NoNewWindow
# ------------------- DONE -------------------
if (Test-Path $distExePath) {
Write-Host "`n[SUCCESS] Packaging complete!"
Write-Host " Output: $distExePath" -ForegroundColor Green
} else {
Write-Host "`n[FAILURE] Packaging failed." -ForegroundColor Red
}

View File

@ -12,7 +12,6 @@ eventlet
# GUI-related dependencies (Qt for GUI components)
Qt.py
qtpy
OdenGraphQt
PyQt5
# Computer Vision & OCR Dependencies