diff --git a/docs/MANUAL_PYTHON_SETUP.md b/docs/MANUAL_PYTHON_SETUP.md new file mode 100644 index 0000000..489dfce --- /dev/null +++ b/docs/MANUAL_PYTHON_SETUP.md @@ -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" + +## 🔍 故障排除 + +### 问题1:Python命令不存在 + +**解决方案**: +- 安装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环境。选择最适合你情况的方法即可。 diff --git a/scripts/test_python_setup_fix.bat b/scripts/test_python_setup_fix.bat new file mode 100644 index 0000000..7cff5fe --- /dev/null +++ b/scripts/test_python_setup_fix.bat @@ -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 diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 1175e6c..38c1c07 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -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: '模板库' }, diff --git a/src/pages/PythonEnvManagerPage.tsx b/src/pages/PythonEnvManagerPage.tsx index 622db1f..ded45ab 100644 --- a/src/pages/PythonEnvManagerPage.tsx +++ b/src/pages/PythonEnvManagerPage.tsx @@ -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 = () => {
+ 如果上面的设置失败,请参考手动设置指南 +
+