Skip to content

Latest commit

 

History

History
89 lines (65 loc) · 2.23 KB

File metadata and controls

89 lines (65 loc) · 2.23 KB

构建Windows EXE文件指南

重要说明

由于您当前在Linux/WSL环境中,构建出的是Linux可执行文件。要构建Windows exe文件,需要在Windows环境中运行PyInstaller。

解决方案

方案1:在Windows环境中构建(推荐)

  1. 将项目文件复制到Windows环境

    • 复制整个项目文件夹到Windows电脑
    • 或者在Windows中克隆项目
  2. 在Windows中安装Python和依赖

    pip install -r requirements.txt
  3. 运行构建脚本

    build_exe.bat

方案2:使用Wine(在Linux中模拟Windows)

  1. 安装Wine

    sudo apt update
    sudo apt install wine
  2. 安装Windows版Python

    # 下载Windows版Python安装包
    wget https://www.python.org/ftp/python/3.11.0/python-3.11.0-amd64.exe
    wine python-3.11.0-amd64.exe
  3. 在Wine中构建

    wine python -m pip install -r requirements.txt
    wine python -m PyInstaller pdf_password_remover.spec

方案3:使用Docker(跨平台构建)

  1. 创建Dockerfile

    FROM python:3.11-windowsservercore
    WORKDIR /app
    COPY . .
    RUN pip install -r requirements.txt
    RUN pyinstaller pdf_password_remover.spec
  2. 构建Docker镜像

    docker build -t pdf-remover-windows .

方案4:使用GitHub Actions(自动化构建)

创建.github/workflows/build.yml文件,实现自动化构建Windows exe文件。

当前构建结果

您当前构建的Linux可执行文件位于:

  • dist/PDF密码移除器 (Linux可执行文件)

此文件可以在Linux系统中运行:

./dist/PDF密码移除器

推荐做法

  1. 最简单的方法:将项目文件复制到Windows电脑,然后运行build_exe.bat
  2. 如果没有Windows环境:可以考虑使用在线服务或虚拟机
  3. 自动化构建:设置GitHub Actions在Windows环境中自动构建

注意事项

  • PyInstaller只能在目标操作系统上构建对应的可执行文件
  • Linux → Linux可执行文件
  • Windows → Windows exe文件
  • macOS → macOS应用程序

要获得真正的Windows exe文件,必须在Windows环境中运行PyInstaller。