由于您当前在Linux/WSL环境中,构建出的是Linux可执行文件。要构建Windows exe文件,需要在Windows环境中运行PyInstaller。
-
将项目文件复制到Windows环境:
- 复制整个项目文件夹到Windows电脑
- 或者在Windows中克隆项目
-
在Windows中安装Python和依赖:
pip install -r requirements.txt
-
运行构建脚本:
build_exe.bat
-
安装Wine:
sudo apt update sudo apt install wine
-
安装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 -
在Wine中构建:
wine python -m pip install -r requirements.txt wine python -m PyInstaller pdf_password_remover.spec
-
创建Dockerfile:
FROM python:3.11-windowsservercore WORKDIR /app COPY . . RUN pip install -r requirements.txt RUN pyinstaller pdf_password_remover.spec
-
构建Docker镜像:
docker build -t pdf-remover-windows .
创建.github/workflows/build.yml文件,实现自动化构建Windows exe文件。
您当前构建的Linux可执行文件位于:
dist/PDF密码移除器(Linux可执行文件)
此文件可以在Linux系统中运行:
./dist/PDF密码移除器- 最简单的方法:将项目文件复制到Windows电脑,然后运行
build_exe.bat - 如果没有Windows环境:可以考虑使用在线服务或虚拟机
- 自动化构建:设置GitHub Actions在Windows环境中自动构建
- PyInstaller只能在目标操作系统上构建对应的可执行文件
- Linux → Linux可执行文件
- Windows → Windows exe文件
- macOS → macOS应用程序
要获得真正的Windows exe文件,必须在Windows环境中运行PyInstaller。