一、安装前言
安装环境准备:
CentOS7.5:16U8G500G
安装包准备:
Anaconda3(Anaconda3-5.3.1-Linux-x86_64.sh)
PaddlePaddle(在线安装)
PaddleHub(在线安装)
PaddleOCR(PaddleOCR-release-2.6)
本文将详细记录安装过程及遇到问题的解决方式,此次安装的之前已经在虚拟机中进行了完整安装并测试通过。根据经验,进行安装总结,注意重点安装涉及到大量的依赖。
PS:本人无pthon开发经验,不要相信官网上说的3句话安装,同时mac上无法成功安装paddleocr最好还是用虚拟机。
二、服务器准备
参照《服务器常规安装过程》
三、安装PaddleOCR在线服务
3.1、安装Anaconda3
#创建文件夹/u01
mkdir /u01
#打开u01
cd /u01
#安装wget
yum install wget
#下载Anaconda3
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh --no-check-certificate
#此处忽略已经下载好了
#安装bzip2
yum install -y bzip2
#授权sh文件执行
chmod 777 -R Anaconda3-5.3.1-Linux-x86_64.sh
#执行安装脚本
./Anaconda3-5.3.1-Linux-x86_64.sh
#安装过程输入协议,文件名等
#一段协议一直回车
#是否认可协议内容,Do you accept the license terms? [yes|no]
yes
#写入环境变量
#Anaconda3 will now be installed into this location:/root/anaconda3
#直接回车
#环境变量写入位置/root/.bashrc
yes
#是否安装vscode此处写no
no
#在环境变量中加入anaconda的lib目录不然后面会出问题
#vi ~/.bashrc
#export LD_LIBRARY_PATH=/root/anaconda3/lib
#新写法
echo "export LD_LIBRARY_PATH=/lib:/lib64:/usr/lib64/:/usr/lib:/root/anaconda3/lib:$LD_LIBRARY_PATH" >> ~/.bashrc
#刷新环境变量
source ~/.bashrc
#验证安装结果anaconda
conda info
##创建conda虚拟机,此处不加python后缀自动按照默认版本安装
conda create -n paddleocr
#进入虚拟机
conda activate paddleocr
3.2、安装Paddle
#默认安装的pip版本太低,首先需要对pip进行升级
pip install --upgrade pip -i https://mirror.baidu.com/pypi/simple
#安装PyHamcrest
pip install PyHamcrest -i https://mirror.baidu.com/pypi/simple
#正式开始安装Paddle
pip install --upgrade paddlepaddle -i https://mirror.baidu.com/pypi/simple
3.3、安装Paddlehub
#执行多次,不然无法安装
pip uninstall numpy
pip install numpy -i https://mirror.baidu.com/pypi/simple
#安装libGL依赖
yum install mesa-libGL.x86_64
#安装Paddlehub
pip install --upgrade paddlehub -i https://mirror.baidu.com/pypi/simple --ignore-installed PyYAML
3.4、编译部署Paddleocr
#安装gcc、g++、unzip,后面编译时候需要使用到
yum install gcc
yum install gcc-c++
yum install unzip
unzip PaddleOCR-release-2.6.zip
mv PaddleOCR-release-2.6 /root/
cd /root/PaddleOCR-release-2.6
#安装所有依赖包这里面的文件有很多
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple
mkdir inference
cd inference
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar && tar xf ch_PP-OCRv3_det_infer.tar
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar && tar xf ch_ppocr_mobile_v2.0_cls_infer.tar
wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar && tar xf ch_PP-OCRv3_rec_infer.tar
cd /root/PaddleOCR-release-2.6/deploy/hubserving/ocr_system/
vi params.py
#修改成绝对路径总共四条
vi params.py
#user_gpu修改成false
vi module.py
#在deploy/hubserving/ocr_system/module.py的from tools.infer.utility import base64_to_cv2前添加
import sys
sys.path.append('../../../')
hub install ../ocr_system
#运行服务
hub serving start -m ocr_system
python test_hubserving_showbase64.py --server_url http://127.0.0.1:8866/predict/ocr_system --image_dir /root/aa/IMG_00003.jpg
四、遇到问题总结
4.1、安装anaconda3会和yum产生冲突
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
/root/anaconda3/lib/liblzma.so.5: version `XZ_5.1.2alpha’ not found (required by /lib64/librpmio.so.3)
#解决方法
在~./bashrc中添加环境变量:“export LD_LIBRARY_PATH=/lib:/lib64:/usr/lib64/:/usr/lib:/root/anaconda3/lib:$LD_LIBRARY_PATH”
是anaconda3在安装过程中写入环境变量导致原来的系统变量冲突
4.2、安装paddlehub会遇到无法卸载PyYAML
ERROR: Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
#解决办法:
在安装paddlehub的安装指令后面加上–ignore-installed PyYAML
4.3安装好hub调试时候发现包错
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in [‘/root/anaconda3/lib/python3.7/site-packages/numpy’]. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.
#解决办法
pip uninstall numpy
#要执行多次彻底删除干净
#重新安装
pip install numpy -i https://mirror.baidu.com/pypi/simple
4.4无法找到_validate_lengths方法
ImportError: cannot import name ‘_validate_lengths’ from ‘numpy.lib.arraypad’ (/root/anaconda3/lib/python3.7/site-packages/numpy/lib/arraypad.py)
修改arraycrop.py文件,由于新版本的numpy方法的名字进行了修改,或者更新numpy为1.15版本也可以