• pix2tex - LaTeX OCR 安装使用记录


    系列文章目录


    文章目录

    • 系列文章目录
    • 前言
    • 一、安装
    • 二、使用
    • 三、
    • 四、报错


    前言

    项目地址:这儿


    一、安装

    版本要求
    Python: 3.7+
    PyTorch: >=1.7.1

    安装:

    pip install torch torchvision torchaudio
    
    • 1
    pip install "pix2tex[gui]
    
    • 1

    注意:Pyside6 和 PyQt6 版本需要保持一致,否则会报 QT 错误

    二、使用

    打开 Windows 终端,输入命令:

    latexocr
    
    • 1

    注意:需要将 latexocr.exe 所在路径添加到系统 Path 路径下,以便找到该可执行文件

    在这里插入图片描述

    在这里插入图片描述

    例如:
    在这里插入图片描述

    三、

    可以识别出来,如果识别有错误,可以直接在 gui 界面修改 Latex 代码,公式会实时更新,修改好之后再复制。

    四、报错

    Traceback (most recent call last):
      File "D:\Software\miniconda3\lib\runpy.py", line 196, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "D:\Software\miniconda3\lib\runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\Scripts\latexocr.exe\__main__.py", line 7, in <module>
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\pix2tex\__main__.py", line 28, in main
        main(arguments)
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\pix2tex\gui.py", line 347, in main
        ex = App(arguments)
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\pix2tex\gui.py", line 28, in __init__
        self.model = cli.LatexOCR(self.args)
      File "D:\Software\miniconda3\lib\contextlib.py", line 79, in inner
        return func(*args, **kwds)
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\pix2tex\cli.py", line 84, in __init__
        self.model.load_state_dict(torch.load(self.args.checkpoint, map_location=self.args.device))
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 993, in load
        with _open_zipfile_reader(opened_file) as opened_zipfile:
      File "C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\torch\serialization.py", line 447, in __init__
        super().__init__(torch._C.PyTorchFileReader(name_or_buffer))
    RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
    
    • 1

    因为下载模型文件时网络错误,导致模型文件下载不全

    路径下:

    C:\Users\kuanli\AppData\Roaming\Python\Python310\site-packages\pix2tex\model\checkpoints

    删除未下载完的 .pth 文件,再次运行即可


  • 相关阅读:
    P2404 自然数的拆分问题
    Promise的面试题考点
    SaaSBase:容智(iBot)RPA是什么?
    细说Binder(Binder核心原理最全解析)
    【Python基础】高级数据类型:初识 “列表” || 列表的增删改查 || del关键字 || 列表的定义
    技术流 | 运维平台大型“生产事故”录播和实战重现
    D. Vus the Cossack and Numbers
    交换综合实验
    【深度学习】LeNet网络架构
    Git入门(建议收藏)
  • 原文地址:https://blog.csdn.net/weixin_46300916/article/details/134191648