MinerU 用于处理pdf 属于是工作流 最后解析成markdown+json
__version__ = "2.1.10"
##构建虚拟环境,执行环境路径(空间较大),避免依赖过大
conda create -p /root/autodl-tmp/data/mineru python=3.10
conda activate /root/autodl-tmp/data/mineru
## 用git下载代码
git clone https://github.com/opendatalab/MinerU.git
cd MinerU
## 项目用uv工具管理,先下个uv
pip install uv
#阿里云的源好像还没有,换清华的
pip install uv -i https://pypi.tuna.tsinghua.edu.cn/simple
## 安装依赖
uv pip install -e .[core] -i https://mirrors.aliyun.com/pypi/simple
#阿里云的源好像403,换清华的
uv pip install -e .[core] --index-url https://pypi.tuna.tsinghua.edu.cn/simple
#依赖超级多,貌似147个(2.1.10) 150个(3.0版本),耐心等待。
## 下载模型(也可以不执行,执行了会下载较多的模型,占用空间)
mineru-models-download
## 执行命令
mineru -p /root/autodl-tmp/data/mineru/input/刘邦的简历.pdf -o /root/autodl-tmp/data/mineru/output -d cuda
mineru -p /root/autodl-tmp/input/DeepSeek专题之企业级智能客服.pdf -o /root/autodl-tmp/output

报错的话
conda install -c nvidia nccl
检查并修复 PyTorch 环境
确保 PyTorch 版本与 CUDA 匹配
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # 替换为您的 CUDA 版本

pip install pymupdf
#新版-d移除了 会自动检测设备 --source 也移除了 使用环境变量来设置
export MINERU_MODEL_SOURCE=modelscope

image.png
设置模型下载位置
# 创建模型目录
mkdir -p /root/autodl-tmp/data/mineru/models
# 写入环境变量
echo 'export MODELSCOPE_CACHE=/root/autodl-tmp/data/mineru/models' >> ~/.bashrc
echo 'export MINERU_MODEL_SOURCE=modelscope' >> ~/.bashrc
source ~/.bashrc
2.1.10版本的
cd /root/autodl-tmp/MinerU/projects/multi_gpu_v2

image.png
#完成以上自定义配置后,回到服务器终端,依次执行如下三条命令安装LitServe服务运行所需要的依赖环境:
pip install -U litserve python-multipart filetype
pip install paddlepaddle-gpu==3.0.0b1 -i https://www.paddlepaddle.org.cn/packages/stable/cu118
# 启动脚本
python server.py
3.0版本移除了litserver 内置了自己的多gpu方案
# 单卡直接用
mineru-api --host 0.0.0.0 --port 8000
# 多卡
mineru-router --host 0.0.0.0 --port 8002 --local-gpus auto

image.png
3.0的同步方法
/file_parse
~~