1. Posts/

PaddleOCR M1 MacBook 安装全记录

·阅读预计 4 分钟
PaddleOCR Homebrew Mac 记录
小北
作者
小北
目录

M1 的 Mac 预装了 python3 环境,我按照 官方提供的文档 开整很难一次成功,于是便有了这份记录

需要准备 #

已经熟悉 Homebrew 操作了的可以不看这段,点击目录直接跳转到【 正式安装 】步骤

brew install pyenv
pyenv install 3.10.14

查看已经安装过的版本:

pyenv versions

可以全局切换到3.10.14

pyenv global 3.10.14

更新环境变量

echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc

使之生效

source ~/.zshrc
uuphy@BEIs-MacBook-Air ~ % which python
/opt/homebrew/opt/python@3.11/libexec/bin/python
uuphy@BEIs-MacBook-Air ~ % which pip
/opt/homebrew/opt/python@3.11/libexec/bin/pip
uuphy@BEIs-MacBook-Air ~ % pip -V
pip 23.3.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)

安装 paddle OCR #

python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install "paddleocr>=2.0.1" --upgrade PyMuPDF==1.21.1

下载测试用的 ppocr_img 图片素材大礼包

切换到 ppocr_img 目录:

cd ppocr_img

执行识别:

paddleocr --image_dir ./imgs/11.jpg --use_angle_cls true --use_gpu false

会出现如下报错:

...
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'inf'?

这里是 numpy 出现了问题

GitHub 上 issues 有说 1.23.5可以工作,于是卸载当前的 numpy ,重装1.23.5版本

pip uninstall numpy
pip install numpy==1.23.5

再次执行识别,搞定

uuphy@BEIs-MacBook-Air ppocr_img % paddleocr --image_dir ./imgs/11.jpg --use_angle_cls true --use_gpu false
[2023/11/21 22:30:58] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, shape_info_filename=None, precision='fp32', gpu_mem=500, image_dir='./imgs/11.jpg', det_algorithm='DB', det_model_dir='/Users/uuphy/.paddleocr/whl/det/ch/ch_PP-OCRv3_det_infer', det_limit_side_len=960, det_limit_type='max', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_sast_polygon=False, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_box_type='quad', det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, det_fce_box_type='poly', rec_algorithm='SVTR_LCNet', rec_model_dir='/Users/uuphy/.paddleocr/whl/rec/ch/ch_PP-OCRv3_rec_infer', rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='/opt/homebrew/lib/python3.11/site-packages/paddleocr/ppocr/utils/ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='/Users/uuphy/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, ocr=True, recovery=False, save_pdf=False, lang='ch', det=True, rec=True, type='ocr', ocr_version='PP-OCRv3', structure_version='PP-Structurev2')
[2023/11/21 22:30:59] ppocr INFO: **********./imgs/11.jpg**********
[2023/11/21 22:30:59] ppocr DEBUG: dt_boxes num : 16, elapse : 0.15544414520263672
[2023/11/21 22:30:59] ppocr DEBUG: cls num  : 16, elapse : 0.07158970832824707
[2023/11/21 22:31:01] ppocr DEBUG: rec_res num  : 16, elapse : 1.6698098182678223
[2023/11/21 22:31:01] ppocr INFO: [[[28.0, 37.0], [302.0, 39.0], [302.0, 72.0], [27.0, 70.0]], ('纯臻营养护发素', 0.9658814072608948)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 81.0], [172.0, 83.0], [172.0, 104.0], [25.0, 101.0]], ('产品信息/参数', 0.9113277792930603)]
[2023/11/21 22:31:01] ppocr INFO: [[[28.0, 115.0], [330.0, 115.0], [330.0, 132.0], [28.0, 132.0]], ('(45元/每公斤,100公斤起订)', 0.8843423128128052)]
[2023/11/21 22:31:01] ppocr INFO: [[[27.0, 145.0], [282.0, 145.0], [282.0, 164.0], [27.0, 164.0]], ('每瓶22元,1000瓶起订)', 0.9211717247962952)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 179.0], [299.0, 179.0], [299.0, 195.0], [26.0, 195.0]], ('【品牌】:代加工方式/OEMODM', 0.966156005859375)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 210.0], [233.0, 210.0], [233.0, 227.0], [26.0, 227.0]], ('【品名】:纯臻营养护发素', 0.8831985592842102)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 241.0], [241.0, 241.0], [241.0, 258.0], [26.0, 258.0]], ('【产品编号】:YM-X-3011', 0.8718084096908569)]
[2023/11/21 22:31:01] ppocr INFO: [[[413.0, 236.0], [430.0, 236.0], [430.0, 303.0], [413.0, 303.0]], ('ODMOEM', 0.9539551734924316)]
[2023/11/21 22:31:01] ppocr INFO: [[[23.0, 271.0], [180.0, 269.0], [180.0, 289.0], [24.0, 290.0]], ('【净含量】:220ml', 0.9348663091659546)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 304.0], [252.0, 304.0], [252.0, 320.0], [26.0, 320.0]], ('适用人群):适合所有肤质', 0.8866198062896729)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 335.0], [343.0, 335.0], [343.0, 352.0], [26.0, 352.0]], ('【主要成分】:鲸蜡硬脂醇、燕麦β-葡聚', 0.924584150314331)]
[2023/11/21 22:31:01] ppocr INFO: [[[27.0, 366.0], [281.0, 366.0], [281.0, 383.0], [27.0, 383.0]], ('糖、椰油酰胺丙基甜菜碱、泛醒', 0.9368206262588501)]
[2023/11/21 22:31:01] ppocr INFO: [[[369.0, 370.0], [477.0, 370.0], [477.0, 387.0], [369.0, 387.0]], ('(成品包材)', 0.8927557468414307)]
[2023/11/21 22:31:01] ppocr INFO: [[[26.0, 397.0], [361.0, 397.0], [361.0, 414.0], [26.0, 414.0]], ('【主要功能】:可紧致头发磷层,从而达到', 0.8677884340286255)]
[2023/11/21 22:31:01] ppocr INFO: [[[28.0, 429.0], [372.0, 429.0], [372.0, 445.0], [28.0, 445.0]], ('即时持久改善头发光泽的效果,给于燥的头', 0.8803372383117676)]
[2023/11/21 22:31:01] ppocr INFO: [[[27.0, 459.0], [136.0, 459.0], [136.0, 479.0], [27.0, 479.0]], ('发足够的滋养', 0.9091582894325256)]

其他 & 需要注意的点 #

对了,如果你重启终端窗口后,我这台 Mac 有个很迷的操作是环境变量 python 会发生改变,变成了 python3pip3

例如 pip install gevent 就需要换成 pip3 install gevent

uuphy@BEIs-MacBook-Air ~ % which python
python not found
uuphy@BEIs-MacBook-Air ~ % which python3
/opt/homebrew/bin/python3
uuphy@BEIs-MacBook-Air ~ % python3 -V   
Python 3.11.6
uuphy@BEIs-MacBook-Air ~ % 
旧的 anaconda 安装记录 #

以下是我之前使用 anaconda 的一些安装记录

brew install --cask anaconda
echo 'export PATH="/opt/homebrew/anaconda3/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

conda -V验证

python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install "paddleocr>=2.0.1"     

Failed building wheel for PyMuPDF 解决办法

pip install "paddleocr>=2.0.1" --upgrade PyMuPDF==1.21.1

issues/9761#issuecomment-1614191475

忘记在哪看的了:

【在新建的虚拟环境中安装】删除 numpy 库

pip uninstall numpy

【在新建的虚拟环境中安装】安装 numpy 库 ,降低版本的

pip install numpy==1.20.3

Related

Mac 安装 brew
·阅读预计 1 分钟
Homebrew Mac 笔记
将域名从 Namesilo 转移到 Cloudflare
·阅读预计 1 分钟
域名 Cloudflare 记录
SSH 免密登录
·阅读预计 2 分钟
SSH 记录