This commit is contained in:
root
2025-07-11 14:37:14 +08:00
parent cd75bf70ea
commit 6b2083a8bb
7 changed files with 1144 additions and 38 deletions

152
docs/QUICK_FIX_GUIDE.md Normal file
View File

@@ -0,0 +1,152 @@
# 快速修复指南 - Python Core 构建问题
## 问题分析
构建失败的原因是 `build.spec` 文件中使用了 `__file__` 变量但在PyInstaller的spec文件中这个变量不可用。
## 快速解决方案
### 方案1使用命令行直接构建推荐
`python_core` 目录下运行:
```cmd
# Windows
python -m PyInstaller --onefile --console --name mixvideo-python-core main_simple.py
# 或者如果要包含完整功能
python -m PyInstaller --onefile --console --name mixvideo-python-core ^
--hidden-import python_core ^
--hidden-import python_core.utils ^
--hidden-import python_core.services ^
main.py
```
### 方案2使用测试批处理文件
直接运行:
```cmd
cd python_core
build_test.bat
```
### 方案3修复spec文件
如果要使用spec文件请使用以下简化版本
```python
# build_fixed.spec
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(
['main.py'],
pathex=['.'],
binaries=[],
datas=[],
hiddenimports=[
'python_core',
'python_core.utils',
'python_core.utils.logger',
'python_core.utils.jsonrpc',
'python_core.services',
'python_core.services.template_manager',
# 添加其他需要的模块
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='mixvideo-python-core',
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,
)
```
## 验证步骤
1. **构建成功后**,在 `python_core/dist/` 目录下会生成 `mixvideo-python-core.exe`
2. **测试可执行文件**
```cmd
dist\mixvideo-python-core.exe --version
dist\mixvideo-python-core.exe --module test --action hello
```
3. **复制到Tauri目录**
```cmd
mkdir ..\src-tauri\binaries
copy dist\mixvideo-python-core.exe ..\src-tauri\binaries\
```
4. **更新Tauri配置**
在 `src-tauri/tauri.conf.json` 中添加:
```json
{
"bundle": {
"externalBin": [
{
"name": "mixvideo-python-core",
"src": "binaries/mixvideo-python-core",
"targets": ["all"]
}
]
}
}
```
## 如果仍然遇到问题
### 检查Python环境
```cmd
python --version
python -m pip list | findstr pyinstaller
```
### 安装必要依赖
```cmd
python -m pip install pyinstaller requests Pillow
```
### 使用最简单的构建
```cmd
cd python_core
python -m PyInstaller --onefile main_simple.py
```
这将创建一个基本的可执行文件,可以用来测试整个流程。
## 下一步
一旦基本构建成功,就可以:
1. 逐步添加更多的隐藏导入
2. 测试完整的功能
3. 集成到Tauri应用中
记住:先让简单版本工作,再逐步增加复杂性。