Fix build-appimage.sh: use venv for PyInstaller, set proper paths

- Create venv with --copies to avoid system pip restrictions (PEP 668)
- Install deps into venv before PyInstaller run
- Use absolute paths for --add-data
This commit is contained in:
Maksim Totmin 2026-05-31 17:48:54 +07:00
parent 81b2ab2173
commit 7a86732953

View File

@ -9,6 +9,7 @@ APP_DIR="$BUILD_DIR/$APP_NAME.AppDir"
PYTHON="${PYTHON:-python3}" PYTHON="${PYTHON:-python3}"
PIP="${PIP:-pip3}" PIP="${PIP:-pip3}"
VENV_DIR="$BUILD_DIR/venv"
ARCH="${ARCH:-x86_64}" ARCH="${ARCH:-x86_64}"
APPIMAGE_OUTPUT="$PROJECT_DIR/$APP_NAME-${ARCH}.AppImage" APPIMAGE_OUTPUT="$PROJECT_DIR/$APP_NAME-${ARCH}.AppImage"
@ -37,9 +38,6 @@ check_deps() {
missing+=("$cmd") missing+=("$cmd")
fi fi
done done
if ! "$PYTHON" -c "import PyInstaller" 2>/dev/null; then
missing+=("pyinstaller (pip install pyinstaller)")
fi
if [ ${#missing[@]} -gt 0 ]; then if [ ${#missing[@]} -gt 0 ]; then
err "Missing dependencies: ${missing[*]}" err "Missing dependencies: ${missing[*]}"
exit 1 exit 1
@ -47,10 +45,15 @@ check_deps() {
} }
install_pyinstaller() { install_pyinstaller() {
if ! "$PYTHON" -c "import PyInstaller" 2>/dev/null; then if [ -f "$VENV_DIR/bin/python" ] && "$VENV_DIR/bin/python" -c "import PyInstaller" 2>/dev/null; then
info "Installing PyInstaller..." return 0
"$PIP" install pyinstaller
fi fi
info "Creating virtual environment..."
"$PYTHON" -m venv --copies "$VENV_DIR"
info "Installing PyInstaller and dependencies..."
"$VENV_DIR/bin/pip" install pyinstaller
# Install project dependencies for bundling
"$VENV_DIR/bin/pip" install -r "$PROJECT_DIR/requirements.txt"
} }
download_appimagetool() { download_appimagetool() {
@ -73,14 +76,14 @@ build_appdir() {
info "Running PyInstaller..." info "Running PyInstaller..."
cd "$PROJECT_DIR" cd "$PROJECT_DIR"
"$PYTHON" -m PyInstaller \ "$VENV_DIR/bin/pyinstaller" \
--onedir \ --onedir \
--name "$APP_NAME" \ --name "$APP_NAME" \
--distpath "$APP_DIR/usr/bin" \ --distpath "$APP_DIR/usr/bin" \
--workpath "$BUILD_DIR/pybuild" \ --workpath "$BUILD_DIR/pybuild" \
--specpath "$BUILD_DIR" \ --specpath "$BUILD_DIR" \
--add-data "src:src" \ --add-data "$PROJECT_DIR/src:$APP_NAME/src" \
--paths src \ --paths "$PROJECT_DIR/src" \
--hidden-import PyQt6.QtMultimedia \ --hidden-import PyQt6.QtMultimedia \
--hidden-import PyQt6.QtMultimediaWidgets \ --hidden-import PyQt6.QtMultimediaWidgets \
--collect-all PyQt6 \ --collect-all PyQt6 \
@ -123,11 +126,13 @@ APPRUN
} }
create_icon() { create_icon() {
# Generate a simple SVG icon or use a placeholder
local icon="$APP_DIR/$APP_NAME.png" local icon="$APP_DIR/$APP_NAME.png"
# Create a minimal 256x256 PNG using Python + Pillow if available local py="$VENV_DIR/bin/python3"
if "$PYTHON" -c "from PIL import Image" 2>/dev/null; then if [ ! -f "$py" ]; then
"$PYTHON" -c " py="$PYTHON"
fi
if "$py" -c "from PIL import Image" 2>/dev/null; then
"$py" -c "
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
img = Image.new('RGBA', (256, 256), (0, 0, 0, 0)) img = Image.new('RGBA', (256, 256), (0, 0, 0, 0))
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
@ -170,8 +175,8 @@ main() {
echo -e "${CYAN}========================================${NC}" echo -e "${CYAN}========================================${NC}"
echo "" echo ""
check_deps
install_pyinstaller install_pyinstaller
check_deps
mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR"
download_appimagetool download_appimagetool
build_appdir build_appdir