正确安装PaddleOCR的方法

发布时间 2023-10-08 13:14:39作者: pu369com

 paddleocr安装起来太费劲了

pip install patch-ng

pip install paddleocr --use-pep517   (失败)

1.首先去github下载:https://github.com/PaddlePaddle/PaddleOCR,然后找个文件夹解压。(从CSDN中点开链接时会提供加速功能,跳转到了https://gitcode.net/mirrors/paddlepaddle/paddleocr?utm_source=csdn_github_accelerator )

2.安装PaddlePaddle

按照官网提供的命令:

python -m pip install paddlepaddle==2.5.1 -i https://mirror.baidu.com/pypi/simple

3 cd到刚才解压的PaddleOCR文件夹中,执行:

pip install -r requirements.txt

红色字提示:ERROR: No matching distribution found for opencv-python==4.2.0.32

 

修改  requirements.txt 直接去掉  ==4.2.0.32

再次执行:pip install -r requirements.txt

执行:pip install paddleocr

在执行到安装PyPDF时出错,提示:error: command 'swig.exe' failed: None

执行:pip install swig

再次执行:pip install paddleocr   终于成功了

2.代码

from paddleocr import PaddleOCR, draw_ocr
 
ocr = PaddleOCR(use_angle_cls=True, use_gpu=False)
img_path = r'F:\1.png'
result = ocr.ocr(img_path, cls=True)
for line in result:
    print(line)

  首次在CMD中运行代码时,下载了3 个文件到 C:\Users\用户名\.paddleocr\whl\rec\ch\ch_PP-OCRv4_rec_infer 目录,分别是:inference.pdiparams    inference.pdiparams.info  inference.pdmodel

删除掉下载后解压的paddleocr-develop目录,在IDLE中再次执行代码,IDLE中输出结果正常,但是有黑框一闪。

 

参考:https://blog.csdn.net/weixin_44063045/article/details/129211758

https://blog.51cto.com/u_15671528/5974388

https://pythonjishu.com/ustjibibiytohrb/

https://blog.csdn.net/weixin_64974855/article/details/132768887

https://www.paddlepaddle.org.cn/

https://blog.csdn.net/weixin_42708301/article/details/119864744