|
Download deploy_guide.md from zdy10046/RamEx: direct link, hf CLI and curl.
- Browser
- Download file 3.47 kB
-
https://huggingface.co/spaces/zdy10046/RamEx/resolve/main/deploy_guide.md
- Command line
-
hf download hf://spaces/zdy10046/RamEx/deploy_guide.md
-
curl -L -o deploy_guide.md https://huggingface.co/spaces/zdy10046/RamEx/resolve/main/deploy_guide.md
3.47 kB
| # Web环境部署指南 | |
| ## 环境信息 | |
| - **原环境**: macOS (darwin 24.5.0) | |
| - **Python版本**: 3.8.16 | |
| - **环境名称**: web | |
| - **目标平台**: Linux | |
| ## 方法1: 使用conda environment.yml (推荐) | |
| ### 在Linux系统上复现环境 | |
| 1. **安装Anaconda或Miniconda** | |
| ```bash | |
| # 如果还没有安装conda | |
| wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | |
| bash Miniconda3-latest-Linux-x86_64.sh | |
| ``` | |
| 2. **创建新环境** | |
| ```bash | |
| # 使用environment.yml文件创建环境 | |
| conda env create -f environment.yml | |
| # 激活环境 | |
| conda activate web | |
| ``` | |
| 3. **验证安装** | |
| ```bash | |
| python --version # 应该显示 Python 3.8.16 | |
| pip list | grep Django # 检查Django是否正确安装 | |
| ``` | |
| ## 方法2: 使用pip requirements (备选) | |
| 如果conda方法遇到问题,可以使用pip方式: | |
| 1. **创建conda环境** | |
| ```bash | |
| conda create -n web python=3.8.16 | |
| conda activate web | |
| ``` | |
| 2. **安装依赖包** | |
| ```bash | |
| # 使用精确版本的requirements文件 | |
| pip install -r requirements_exact.txt | |
| # 或者使用简化版本的requirements文件 | |
| pip install -r requirements.txt | |
| ``` | |
| ## 方法3: 手动安装核心包 | |
| 如果上述方法都有问题,可以手动安装核心包: | |
| ```bash | |
| # 创建环境 | |
| conda create -n web python=3.8.16 | |
| conda activate web | |
| # 安装核心Django相关包 | |
| pip install Django==4.2 | |
| pip install djangorestframework==3.14.0 | |
| pip install django-bootstrap5==23.1 | |
| pip install drf-yasg==1.21.6 | |
| # 安装数据处理包 | |
| pip install pandas==2.0.2 | |
| pip install numpy==1.24.3 | |
| pip install rpy2==3.5.17 | |
| # 安装服务器相关 | |
| pip install gunicorn==20.1.0 | |
| pip install psycopg2-binary==2.9.6 | |
| # 其他必要包 | |
| pip install cryptography==44.0.2 | |
| pip install Pillow==9.5.0 | |
| pip install python-dotenv==1.0.0 | |
| pip install pytz==2023.3 | |
| ``` | |
| ## 注意事项 | |
| ### 1. 平台差异 | |
| - **rpy2**: 在Linux上可能需要预先安装R语言环境 | |
| ```bash | |
| # Ubuntu/Debian | |
| sudo apt-get install r-base r-base-dev | |
| # CentOS/RHEL | |
| sudo yum install R R-devel | |
| ``` | |
| - **mysqlclient**: 需要MySQL开发包 | |
| ```bash | |
| # Ubuntu/Debian | |
| sudo apt-get install libmysqlclient-dev | |
| # CentOS/RHEL | |
| sudo yum install mysql-devel | |
| ``` | |
| ### 2. 可能的兼容性问题 | |
| - 某些包的版本可能在Linux上不完全兼容 | |
| - 建议首先尝试安装,如果遇到问题再单独处理特定包 | |
| ### 3. 生产环境建议 | |
| - 移除或注释开发工具包(如django-debug-toolbar) | |
| - 考虑添加whitenoise用于静态文件处理 | |
| - 确保所有安全相关的包都是最新版本 | |
| ## 验证环境 | |
| 创建环境后,运行以下测试来验证环境是否正确: | |
| ```python | |
| # test_environment.py | |
| import django | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| print(f"Django version: {django.get_version()}") | |
| print(f"Pandas version: {pd.__version__}") | |
| print(f"NumPy version: {np.__version__}") | |
| # 测试Django是否可以正常工作 | |
| from django.conf import settings | |
| settings.configure(DEBUG=True, SECRET_KEY='test') | |
| print("Django configuration successful!") | |
| ``` | |
| 运行测试: | |
| ```bash | |
| python test_environment.py | |
| ``` | |
| ## 文件清单 | |
| 该部署包含以下文件: | |
| - `environment.yml`: 完整的conda环境配置 | |
| - `requirements.txt`: 生产环境的简化依赖列表 | |
| - `requirements_exact.txt`: 包含所有确切版本的完整依赖列表 | |
| - `deploy_guide.md`: 本部署指南 | |
| 选择最适合你的部署环境的方法即可。 |