安装LaTeX-OCR首先需要安装Python。在系统自带的应用商店Microsoft Store搜索Python,点击最新版本Python 3.12下载即可。
Win11按底部状态栏windows徽标在搜索框内搜索 powershell 或者按快捷键 “win 键 + R” ,打开“运行”窗口,输入 powershell 并回车,打开命令行。
复制以下代码:pip3 install torch?torchvision?torchaudio -i?https://pypi.tuna.tsinghua.edu.cn/simple?some-package
在powershell中按鼠标右键粘贴键入内容,回车。
复制以下代码:pip3 install pix2tex[gui] -i?https://pypi.tuna.tsinghua.edu.cn/simple?some-package
在powershell中按鼠标右键粘贴键入内容,回车。
在powershell中键入latexocr并回车即可。
WARNING: The script isympy.exe is installed in 'C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts' which is not on PATH.
? Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
将Warning信息中的环境变量手动编辑进系统环境变量即可。
1、首先右击计算机进入属性然后选择其中的高级系统设置。(Win10)
在底部任务栏右键进入任务栏设置,选择系统-系统信息-高级系统设置(Win11)
?
?
2、点击进入高级中的环境变量,进入环境变量编辑界面。
3、在下方的系统变量中,双击打开path路径
添加python和python目录里的Scripts目录路径即可用microsoft商店装的Python可以在参考这个目录:C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\Scripts
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\19528\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python311\\site-packages\\transformers\\models\\deprecated\\trajectory_transformer\\convert_trajectory_transformer_original_pytorch_checkpoint_to_pytorch.py'
HINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
这个错误信息表明安装包时发生了OSError错误,可能是因为没有启用Windows长路径支持。你可以参考https://pip.pypa.io/warnings/enable-long-paths上的说明来启用长路径支持。
根据Microsoft官网的方案,可以修改注册表或者直接在PowerShell用代码解决,代码如下:
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
按照最后一步在powershell输入latexocr后输出:
download weights v0.0.1 to path C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pix2tex\model\checkpoints
Traceback (most recent call last):
...
?File "C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\requests\adapters.py", line 517, in send
? ? raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /lukas-blecher/LaTeX-OCR/releases/download/v0.0.1/weights.pth (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')))
可能是墙限制了对 GitHub 的访问。
解决方法:手动安装训练数据weights.pth
下载网址:
https://download.csdn.net/download/Andy_Xie007/88760727?spm=1001.2014.3001.5503
https://github.com/lukas-blecher/LaTeX-OCR/releases/download/v0.0.1/weights.pth(需要本地反代访问github)
安装位置:
在python环境变量路径(如C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311)下搜索文件夹名称:checkpoints,将下载下来的weights.pth复制到搜索到的路径下,如
C:\Users\19528\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pix2tex\model\checkpoints(仅供参考)
详见https://www.yuucn.com/a/1548030.html(安装训练数据)
参考文章:
[ 环境搭建篇 ] 安装python环境并配置环境变量(附python3.10.3安装包)_如何找到需要添加到环境变量的python-CSDN博客深度学习实战10-数学公式识别-将图片转换为Latex(img2Latex) - 电脑学习网