type
status
date
slug
summary
tags
category
icon
password
一、项目背景
考虑到MinerU的环境配置相对复杂,特此制作了Windows系统的环境一键整合包,方便用户使用。该整合包包含使用说明文档,适用于Windows11系统。
二、下载地址
MinerU环境一键整合包下载地址 (含历史版本)
三、使用说明
使用非常简单,无需复杂安装部署,下载后解压即可使用。已经包含了模型,整合了Python单独的环境以及所需的包,独立不干扰系统环境,小白也能轻松上手,也可用于二次开发。
- 使用前准备:需要安装里面的cuda,安装cuda的教程可自行百度,如果已经安装请忽略。如果之前安装有cuda报错,可卸载之前的cuda,安装整合包中的cuda11.8版本。
- 解压注意事项:解压后可运行,可解压到任意位置,但路径最好不要包含中文或有空格的文件夹,以免导致各种问题

3.1 网页版
点击运行
运行网页版.bat, 运行网页版界面,除此之外, 将页数限制改成了100000, 新增支持一次处理多个文件, 文件格式支持多种

3.2 桌面版
点击
运行桌面版.bat, 运行桌面版界面, 功能和网页版的差不多, 喜欢用哪个选哪个
四、文件说明
models  # 模型目录
output # 输出文件夹
projects # 项目文件夹
python # 环境文件夹
magic-pdf.json # magic-pdf配置文件
small_ocr.pdf # PDF测试文件
运行桌面版.bat # 桌面版运行脚本
运行网页版.bat # 网页版运行脚本五、脚本说明
如果需要使用脚本命令, 或需要是二次开发, 请解压到
D:\MinerU, 因为生成的exe硬编码了路径, 所以只能解压到这个位置, 不然路径会出错.5.1 运行脚本方式1
可以先把
D:\MinerU\python 和D:\MinerU\python\Scripts 这两个目录添加到系统环境变量, 这样可以直接运行官方命令magic-pdf --help
Usage: magic-pdf [OPTIONS]
Options:
  -v, --version                display the version and exit
  -p, --path PATH              local filepath or directory. support PDF, PPT,
                               PPTX, DOC, DOCX, PNG, JPG files  [required]
  -o, --output-dir PATH        output local directory  [required]
  -m, --method [ocr|txt|auto]  the method for parsing pdf. ocr: using ocr
                               technique to extract information from pdf. txt:
                               suitable for the text-based pdf only and
                               outperform ocr. auto: automatically choose the
                               best method for parsing pdf from ocr and txt.
                               without method specified, auto will be used by
                               default.
  -l, --lang TEXT              Input the languages in the pdf (if known) to
                               improve OCR accuracy.  Optional. You should
                               input "Abbreviation" with language form url: ht
                               tps://paddlepaddle.github.io/PaddleOCR/en/ppocr
                               /blog/multi_languages.html#5-support-languages-
                               and-abbreviations
  -d, --debug BOOLEAN          Enables detailed debugging information during
                               the execution of the CLI commands.
  -s, --start INTEGER          The starting page for PDF parsing, beginning
                               from 0.
  -e, --end INTEGER            The ending page for PDF parsing, beginning from
                               0.
  --help                       Show this message and exit.
## show version
magic-pdf -v
## command line example
magic-pdf -p {some_pdf} -o {some_output_dir} -m auto比如对一个路径为
PDF目录里边的文件进行遍历转换处理, 命令行为magic-pdf -p PDF目录 -o PDF输出目录 -m auto5.2 运行脚本方式2
如果不添加到环境变量, 在D:\MinerU 目录下, 使用右键打开命令行输入
./python/Scripts/magic-pdf.exe -p PDF目录 -o PDF输出目录 -m auto或者直接用绝对路径
D:/MinerU/python/Scripts/magic-pdf.exe -p PDF目录 -o PDF输出目录 -m auto

对python的包进行管理, 命令为
./python/python.exe -m pip install xxx
./python/python.exe -m pip install -U "magic-pdf[full]"如果确实需要放到别的盘使用, 则需要重装pip和magic-pdf等你需要的包, 重装的时候会重新生成所在目录
python\Scripts的exe文件./python/python.exe -m pip install -U "magic-pdf[full]"六、更新
如果要自行更新(前提官方模型没更新, api没变动)
可以使用下面更新命令进行更新(不同的源可能magic-pdf版本不一样)
./python/python.exe -m pip install -U "magic-pdf[full]"更新完需要修改文件, 不然会提示模型路径出错
修改文件
D:\MinerU\python\Lib\site-packages\magic_pdf\libs\config_reader.py将11行左右
# 定义配置文件名常量  CONFIG_FILE_NAME = os.getenv('MINERU_TOOLS_CONFIG_JSON', 'magic-pdf.json')改为
# 定义配置文件名常量  # CONFIG_FILE_NAME = os.getenv('MINERU_TOOLS_CONFIG_JSON', 'magic-pdf.json')  
  
# 获取当前目录  current_dir = os.getcwd()  
print("当前目录为: ", current_dir)  
CONFIG_FILE_NAME = os.path.join(current_dir, "magic-pdf.json")  
print("当前配置路径为: ", CONFIG_FILE_NAME)将66行左右
models_dir = config.get('models-dir')改为
models_dir = config.get('models-dir')
models_dir = os.path.join(current_dir, models_dir)
print(f"当前模型目录为: {models_dir}")

修改文件
D:\MinerU\python\Lib\site-packages\paddleocr\paddleocr.py将66行左右
BASE_DIR = os.path.expanduser("~/.paddleocr/")改为
BASE_DIR = os.path.join(os.getcwd(), "models", "paddleocr")  
print(f"paddleocr模型的目录为: {BASE_DIR}")这样更新完模型的路径才不会报错
命令行使用
官方的命令使用
 magic-pdf -p {some_pdf} -o {some_output_dir} -m auto在MinerU目录右键启动cmd, 或者启动cmd切换到MinerU目录, 运行下列命令
 ./python/Scripts/magic-pdf.exe -p {some_pdf} -o {some_output_dir} -m auto例如
 ./python/Scripts/magic-pdf.exe -p small_ocr.pdf或者路径填magic-pdf.exe所在的绝对路径, 例如
 G:/MinerU/python/Scripts/magic-pdf.exe -p small_ocr.pdf如果包损坏了, 可以通过下面两个命令进行重新下载更新
./python/python.exe -m pip install -U magic-pdf[full]
./python/python.exe -m pip install -r ./projects/web_demo/requirements.txt七、开发使用
在pycharm里环境变量填
python/python.exe所在目录
八、疑难解答
如运行遇到报错,建议留言附带电脑配置信息(如i7-11800H, 内存16G, 显卡RTX 3060 12G),所用系统(如Win11、Win10等),显卡驱动版本,cuda版本等,以便更好地排查问题。