This commit is contained in:
root 2025-07-11 15:26:22 +08:00
parent efcaa2e493
commit 7cfb28c635
4 changed files with 320 additions and 10 deletions

217
docs/MANUAL_PYTHON_SETUP.md Normal file
View File

@ -0,0 +1,217 @@
# 手动Python环境设置指南
## 🎯 概述
如果自动设置嵌入式Python失败可以按照这个指南手动设置。
## 🔧 方法1手动运行设置脚本
### 1. 检查脚本是否存在
```cmd
# 检查Python设置脚本
dir scripts\setup_embedded_python.py
dir scripts\setup_embedded_python.bat
```
### 2. 手动运行Python脚本
```cmd
# 切换到项目根目录
cd /d "你的项目路径"
# 运行Python设置脚本
python scripts\setup_embedded_python.py
```
### 3. 手动运行批处理脚本
```cmd
# 运行批处理脚本
scripts\setup_embedded_python.bat
```
## 🔧 方法2完全手动设置
如果脚本无法运行,可以完全手动设置:
### 1. 下载Python嵌入式版本
1. 访问 [Python官网](https://www.python.org/downloads/windows/)
2. 下载 `python-3.11.0-embed-amd64.zip`
3. 解压到 `src-tauri/python-embed/` 目录
### 2. 设置pip
```cmd
# 进入Python嵌入式目录
cd src-tauri\python-embed
# 下载get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
# 修改python311._pth文件
# 将 #import site 改为 import site
# 安装pip
python.exe get-pip.py
```
### 3. 安装依赖包
```cmd
# 在python-embed目录中
python.exe -m pip install requests
python.exe -m pip install Pillow
python.exe -m pip install certifi
```
### 4. 复制python_core模块
```cmd
# 从项目根目录
xcopy python_core src-tauri\python-embed\python_core /E /I
```
### 5. 测试安装
```cmd
# 测试Python
src-tauri\python-embed\python.exe --version
# 测试依赖
src-tauri\python-embed\python.exe -c "import requests, PIL; print('OK')"
# 测试python_core
src-tauri\python-embed\python.exe -c "import python_core; print('python_core OK')"
```
## 🔧 方法3使用系统Python
如果嵌入式Python设置困难可以使用系统Python
### 1. 安装系统Python
1. 下载并安装 [Python 3.8+](https://www.python.org/downloads/)
2. 确保添加到PATH
### 2. 安装依赖
```cmd
pip install requests Pillow certifi
```
### 3. 设置环境变量
```cmd
# 强制使用系统Python
set MIXVIDEO_FORCE_SYSTEM_PYTHON=1
```
### 4. 启动应用
```cmd
cargo tauri dev
```
## 🧪 验证设置
### 1. 检查Python环境管理页面
1. 启动应用:`cargo tauri dev`
2. 访问 `/python-env-manager`
3. 查看环境状态:
- 绿色:设置成功
- 红色:需要进一步设置
### 2. 测试基本功能
在Python环境管理页面中
1. 点击"刷新"按钮
2. 尝试安装一个测试包(如 `requests`
3. 查看已安装包列表
### 3. 测试Python Core功能
1. 访问 `/python-core-test`
2. 运行基础功能测试
3. 检查是否显示"Using embedded Python"或"Using system Python"
## 🔍 故障排除
### 问题1Python命令不存在
**解决方案**
- 安装Python并添加到PATH
- 或使用完整路径:`C:\Python311\python.exe`
### 问题2权限问题
**解决方案**
- 以管理员权限运行命令提示符
- 或选择用户目录进行安装
### 问题3网络问题
**解决方案**
- 检查防火墙设置
- 使用国内镜像:
```cmd
python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ requests
```
### 问题4模块导入失败
**解决方案**
- 检查PYTHONPATH设置
- 确保python_core目录结构正确
- 验证__init__.py文件存在
## 📋 目录结构检查
设置完成后,目录结构应该如下:
```
your-project/
├── src-tauri/
│ ├── python-embed/ # 嵌入式Python如果使用
│ │ ├── python.exe
│ │ ├── python311.dll
│ │ ├── Lib/
│ │ ├── Scripts/
│ │ └── python_core/ # 你的Python模块
│ └── tauri.conf.json
├── python_core/ # 原始Python代码
└── scripts/
├── setup_embedded_python.py
└── setup_embedded_python.bat
```
## 🎯 推荐方案
根据你的情况选择:
### 对于开发者
- 使用系统Python方法3
- 更容易调试和开发
### 对于最终用户
- 使用嵌入式Python方法1或2
- 用户无需安装Python
### 对于企业部署
- 使用嵌入式Python
- 确保环境一致性
## 📞 获取帮助
如果仍然遇到问题:
1. **检查日志**:查看控制台输出
2. **验证环境**确认Python版本和依赖
3. **简化测试**:先测试最基本的功能
4. **查看文档**:参考相关技术文档
---
通过这些方法你应该能够成功设置Python环境。选择最适合你情况的方法即可。

View File

@ -0,0 +1,62 @@
@echo off
REM 测试Python设置修复
echo 🔧 Testing Python Setup Fix...
echo.
echo 📋 This script will test the Python environment setup fixes:
echo.
echo 1. 📁 Checking if setup scripts exist...
if exist "scripts\setup_embedded_python.py" (
echo ✅ Python setup script found
) else (
echo ❌ Python setup script NOT found
)
if exist "scripts\setup_embedded_python.bat" (
echo ✅ Batch setup script found
) else (
echo ❌ Batch setup script NOT found
)
echo.
echo 2. 🐍 Testing Python availability...
python --version >nul 2>&1
if errorlevel 1 (
echo ❌ Python not available in PATH
echo You may need to install Python or add it to PATH
) else (
echo ✅ Python is available
python --version
)
echo.
echo 3. 📂 Checking current directory...
echo Current directory: %CD%
echo.
echo 4. 🧪 Testing manual script execution...
echo.
echo You can manually test the setup scripts:
echo.
echo Option A - Python script:
echo python scripts\setup_embedded_python.py
echo.
echo Option B - Batch script:
echo scripts\setup_embedded_python.bat
echo.
echo 5. 🚀 Starting Tauri application...
echo.
echo After the app starts:
echo 1. Go to Python Environment Manager page
echo 2. Try the "设置嵌入式Python" button
echo 3. If that fails, try "简化设置(批处理)" button
echo 4. Check the console for detailed error messages
echo.
pause
echo Starting Tauri dev server...
cargo tauri dev

View File

@ -20,7 +20,6 @@ const Sidebar: React.FC = () => {
const navItems = [
{ path: '/', icon: Home, label: '首页' },
{ path: '/editor', icon: Video, label: '编辑器' },
{ path: '/ai-video', icon: Sparkles, label: 'AI 视频' },
{ path: '/text-video-generator', icon: Wand2, label: 'AI 内容生成' },
{ path: '/templates', icon: Layout, label: '模板库' },

View File

@ -131,6 +131,23 @@ const PythonEnvManagerPage: React.FC = () => {
}
}
// 简化设置嵌入式Python使用批处理脚本
const handleSetupEmbeddedPythonSimple = async () => {
if (!confirm('这将使用批处理脚本设置嵌入式Python环境。继续吗')) return
try {
setLoading(true)
await invoke('setup_embedded_python_simple')
await loadEnvStatus() // 重新加载状态
alert('嵌入式Python环境设置完成')
} catch (error) {
console.error('Failed to setup embedded Python (simple):', error)
alert(`设置失败: ${error}`)
} finally {
setLoading(false)
}
}
// 过滤包列表
const filteredPackages = envStatus?.packages.filter(pkg =>
pkg.name.toLowerCase().includes(searchTerm.toLowerCase())
@ -206,14 +223,29 @@ const PythonEnvManagerPage: React.FC = () => {
<div className="text-sm text-red-600">
<strong>:</strong> {envStatus?.embedded.error}
</div>
<button
onClick={handleSetupEmbeddedPython}
disabled={loading}
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50"
>
<Download size={16} />
Python
</button>
<div className="space-y-2">
<button
onClick={handleSetupEmbeddedPython}
disabled={loading}
className="flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 w-full"
>
<Download size={16} />
Python
</button>
<button
onClick={handleSetupEmbeddedPythonSimple}
disabled={loading}
className="flex items-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 disabled:opacity-50 w-full"
>
<Settings size={16} />
</button>
<p className="text-xs text-gray-500 mt-2">
</p>
</div>
</div>
)}
</div>
@ -292,7 +324,7 @@ const PythonEnvManagerPage: React.FC = () => {
onChange={(e) => setNewPackageName(e.target.value)}
placeholder="输入包名,如: requests, numpy, pillow"
className="flex-1 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
onKeyPress={(e) => e.key === 'Enter' && handleInstallPackage(newPackageName)}
onKeyDown={(e) => e.key === 'Enter' && handleInstallPackage(newPackageName)}
/>
<button
onClick={() => handleInstallPackage(newPackageName)}