目录
- 一、安装依赖
- 二、安装conda新环境和sglang
- 三、PDF解析
-
- [1. 运行](#1. 运行)
- [2. 原始 PDF 并排查看结果](#2. 原始 PDF 并排查看结果)
- [3. 更换模型](#3. 更换模型)
- 四、可能出现的问题
-
- [1.note: This error originates from a subprocess, and is likely not a problem with pip.](#1.note: This error originates from a subprocess, and is likely not a problem with pip.)
- 2.转换单个PDF命令运行时
- [3.ImportError: libnccl.so.2: cannot open shared object file: No such file or directory](#3.ImportError: libnccl.so.2: cannot open shared object file: No such file or directory)
- 4.已经执行了正常命令,但是需要下载sglang
项目地址:
https://github.com/allenai/olmocr
一、安装依赖
bash
sudo apt-get update
sudo apt-get install poppler-utils ttf-mscorefonts-installer msttcorefonts fonts-crosextra-caladea fonts-crosextra-carlito gsfonts lcdf-typetools
二、安装conda新环境和sglang
bash
conda create -n olmocr python=3.11
conda activate olmocr
git clone https://github.com/allenai/olmocr.git
cd olmocr
# If running on CPU, run this:
pip install -e .
# 如果没有权限,可以安装到用户目录下
pip install --user -e .
# If running on GPU, run this instead:
pip install -e .[gpu] --find-links https://flashinfer.ai/whl/cu124/torch2.4/flashinfer/
GPU下使用还需要安装sglang
bash
pip install --upgrade pip
pip install uv
uv pip install "sglang[all]>=0.4.4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python
如果网络问题装不上也可以手动安装wheel,下载好wheel文件之后,sftp传到服务器上,然后直接下载
bash
# 在这里下载
https://github.com/flashinfer-ai/flashinfer/releases/download/v0.2.3/flashinfer_python-0.2.3+cu124torch2.5-cp38-abi3-linux_x86_64.whl
特别慢这边
安装好之后再安装sglang
bash
uv pip install "sglang[all]>=0.4.4"

启动运行命令之后会安装模型权重文件,十几个G,还是很大的。

三、PDF解析
1. 运行
bash
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/horribleocr.pdf
测试了两个pdf文件

输出的是.jsonl,所以看起来并没有换行,看的不清楚
转换多个PDF的命令
bash
python -m olmocr.pipeline ./localworkspace --pdfs tests/gnarly_pdfs/*.pdf
2. 原始 PDF 并排查看结果
bash
python -m olmocr.viewer.dolmaviewer localworkspace/results/output_*.jsonl


3. 更换模型
命令中可以增加模型的更换
bash
--model MODEL List of paths where you can find the model to convert this pdf. You can specify several different paths here, and the script will try to use the
one which is fastest to access
四、可能出现的问题
1.note: This error originates from a subprocess, and is likely not a problem with pip.
从报错信息来看,问题出在 pip install -e . 时无法创建 olmocr.egg-info 目录,原因是 权限不足(Permission denied)。以下是解决方法:
- 检查当前用户权限
确保你对项目目录(/data/huyuqiang/llf/ocr/olmocr)有写权限。可以通过以下命令检查:
bash
ls -ld /data/huyuqiang/llf/ocr/olmocr
如果权限不足,可以尝试修改目录权限:
bash
sudo chown -R $USER:$USER /data/huyuqiang/llf/ocr/olmocr
sudo chmod -R u+rw /data/huyuqiang/llf/ocr/olmocr
- 使用虚拟环境
如果你没有使用虚拟环境,建议创建一个虚拟环境并激活它,这样可以避免权限问题:
bash
python -m venv venv # 创建虚拟环境
source venv/bin/activate # 激活虚拟环境
pip install -e . # 在虚拟环境中安装
- 指定 --user 选项
如果你没有管理员权限,可以尝试使用 --user 选项安装到用户目录:
bash
pip install --user -e .
2.转换单个PDF命令运行时
File "/data/huyuqiang/llf/ocr/olmocr/olmocr/pipeline.py", line 26, in
import torch
File "/data/huyuqiang/anaconda3/envs/olmocr/lib/python3.11/site-packages/torch/init .py", line 367, in
from torch._C import * # noqa: F403
^^^^^^^^^^^^^^^^^^^^^^
ImportError: libcupti.so.12: cannot open shared object file: No such file or directory

这个错误表示系统找不到 CUDA Profiling Tools Interface (CUPTI) 库文件 libcupti.so.12。这是 CUDA 工具包的一部分,通常在安装 CUDA toolkit 时应该包含这个库。
bash
sudo apt-get install cuda-toolkit-12-0
# 编辑 ~/.bashrc 文件
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ln -s /usr/local/cuda/extras/CUPTI/lib64/libcupti.so.12 /usr/local/lib/libcupti.so.12
3.ImportError: libnccl.so.2: cannot open shared object file: No such file or directory
这个错误表明在运行代码时,PyTorch 无法找到 libnccl.so.2 这个共享库文件。libnccl.so.2 是 NVIDIA 的 NCCL(NVIDIA Collective Communications Library)库的一部分,通常用于多 GPU 通信。以下是解决这个问题的步骤:
- 检查是否安装了 NCCL
NCCL 是 NVIDIA 的库,通常与 CUDA 一起安装。你可以通过以下命令检查是否安装了 NCCL:
bash
ls /usr/lib/x86_64-linux-gnu/libnccl*
- 安装 NCCL
如果 NCCL 未安装,可以通过以下步骤安装:
方法 1:通过 NVIDIA 官方安装
访问 NCCL 下载页面。
根据你的系统(Ubuntu/CentOS 等)和 CUDA 版本下载对应的 NCCL 包。
安装下载的包。例如,对于 Ubuntu:

bash
conda install -c nvidia nccl
4.已经执行了正常命令,但是需要下载sglang
https://docs.sglang.ai/start/install.html
bash
pip install --upgrade pip
pip install uv
uv pip install "sglang[all]>=0.4.4" --find-links https://flashinfer.ai/whl/cu124/torch2.5/flashinfer-python