mxivideo/docs/MANUAL_PYTHON_SETUP.md

218 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 手动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环境。选择最适合你情况的方法即可。