离线部署PaddleOCR

​​​​​文章目录




前言

        因为工作原因,需要在离线内网环境下部署PaddleOCR,由于Paddle仅支持3.7以上版本的Python,我们选择3.8版本的Python进行安装,并进行记录全部过程。



一、安装gcc包

首先安装Python的一些依赖包

sudo dpkg -i xxxxxxxxx.deb

安装python需要先安装gcc,否则在进行configure时会出现configure: error: no acceptable C compiler found in $PATH的错误

安装gcc的依赖包

安装gcc之前需要安装三个依赖包gmp-4.3.2、mpc-0.8.1、mpfr-2.4.2

tar -xvf gmp-4.3.2.tar.bz2   # bz2格式的文件使用-xvf进行解压

./configure --prefix=/usr/local/gcc/gmp-4.3.2 ;

make&&make install

 ./configure --prefix=/usr/local/gcc/mpfr-2.4.2 --with-gmp=/usr/local/gcc/gmp-4.3.2/;

make&&make install

 ./configure --prefix=/usr/local/gcc/mpc-0.8.1 --with-gmp=/usr/local/gcc/gmp-4.3.2/ --with-mpfr=/usr/local/gcc/mpfr-2.4.2/;

make&&make install

一定要按照顺序来做,不然会因为依赖关系而报错。

******

【如果报错whether make sets $(MAKE)... no,或configure: error: could not find a working compiler

则安装一下make-4.1.6包,可选择两种方式,第一种是直接dpkg -i xxxx.deb进行安装,另一种是通过挂载本地iso文件进行安装,这里选择第二种。

挂载本地iso文件(在挂载镜像源时注意选择路径/media/cdrom/,不然可能会在apt install时报错cannot find disk的错误,导致无法进行安装)

sudo mkdir /media/cdrom 

sudo mount -t iso9660 -o loop /xxx/xxx/ubuntu-16.04.2-server-amd64.iso /media/cdrom/

#将在线源修改本地的apt源地址,这里修改的是/etc/apt/下的sources.list文件,将deb在线       #apt源注释掉

sudo apt-cdrom -m -d=/media/cdrom add

sudo apt-get update

sudo apt-get upgrade

挂载完之后可输入mount   验证是否完成挂载,若最后一行是挂载的路径,则挂载成功。挂载完成后使用apt install 安装make、build-essential、g++等文件。

如果出现configure:error:no usable m4 in$path or /user/5bin 的问题,则安装一下m4.tar.gz包】

tar -zxvf m4-1.4.13.tar.gz

cd m4-1.4.13

./configure &&make&&make install

---------------------------------------------------------------------------------------------------------------------------------

安装gcc

tar -zxvf gcc-5.4.0.tgz

cd gcc-5.4.0

 ./configure --prefix=/usr/local/gcc-5.4.0  --enable-threads=posix --disable-checking --desable-multilib --with-gmp=/usr/local/gcc/gmp-4.3.2/ --with-mpfr=/usr/local/gcc/mpfr-2.4.2/ --with-mpc=/usr/local/gcc/mpc-0.8.1/

make&&make install

特别提醒!如果直接make,会出现错误 error: cannot compute suffix of object files: cannot compile。这是需要在  /etc/profile里面加上以下内容或直接使用此命令:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gcc/mpc-0.9/lib:/usr/local/gcc/gmp-5.0.1/lib:/usr/local/gcc/mpfr-3.1.0/lib

然后source /etc/profile更新配置

编译时间比较长请耐心等待,可使用make -jn进行加速,n的为想要使用的进程数。

make的时候如果出现下面的错误需要把libmpfr.so.1、libmpc.so.2、libgmp.so.3的地址加到LD_LIBRARY_PATH中,文件任何一个不存在都会出现问题,如下

Checking for suffix of object files… configure: error: in `/home/wulei/sourcecode/gcc-4.6.2/i686-pc-linux-gnu/libgcc’:

configure: error: cannot compute suffix of object files: cannot compile

See `config.log’ for more details.

make[2]: *** [configure-stage1-target-libgcc] error 1

        在出现问题时,可以查看/gcc-4.6.2/x86_64-unknown-linux-gnu/libgcc 下的config.log文件,查看是否丢失文件,丢失的是那个文件,使用find / -name xxxx.so.n 查找文件,并拷贝到/usr/lib/目录下,然后加入到环境变量,make clean ,重新编译。

添加环境变量

先使用echo $LD_LIBRARY_PATH,看看LD_LIBRARY_PATH有没有保存内容,如果没有这几个文件则添加路径,直接使用命令,或者在/etc/profile 中添加

LD_LIBRARY_PATH=/usr/lib/libmpfr.so.1

LD_LIBRARY_PATH=/usr/lib/libmpc.so.2

LD_LIBRARY_PATH=/usr/lib/libgmp.so.3

make install时出现错误  while loading shared libraries libmpc.so.2 缺少动态连接库,解决方法如下:

sudo find / -name libmpc.so.2

ln -s /usr/local/gcc/mpc-0.8.1/lib/libmpc.so.2 /usr/lib/    #查到的libmpc.so.2的路径

sudo ldconfig

在使用多线程编译gcc的时候可能会报错,可以先make  然后看看问题出在哪里  然后再进行编译

安装完成后 输入gcc --version   看是否安装成功

安装openssl

tar -xzvf openssl-1.0.2a.tar.gz

./config --prefix=/usr/local --openssldir=/usr/local/openssl

make && make install

在/usr/local目录下找到lib和include目录,(注意openssl的库是被安装到lib还是lib64,这步很重要)
找到路径/usr/local/lib、/usr/local/include,后面的步骤会用到这两个路径

二、安装python3.8

        编译安装python之前需要安装libffi-devel ***否则pip的时候会出错

安装python3.8

1、自行下载Python-3.8.8.tgz文件

2、提取文件

tar -zxvf Python-3.8.8.tgz

 3、在Modules找到Setup.dist文件,按如下步骤修改,使编译Python的时候能找到刚才安装的openssl的库
1)找到SSL相关配置
#SSL=/usr/local/ssl
#_ssl _ssl.c \
# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
# -L$(SSL)/lib -lssl -lcrypto

2) 由于openssl是被安装在/usr/local目录下的lib和include目录的不是安装在/usr/local/ssl目录,所有把步骤1)找到的4行的注释去掉,如下修改
SSL=/usr/local
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

3、准备从源码编译Python

cd Python-3.8.8 && ./configure prefix=/usr/local/python3 --enable-optimizations

4、编译Python

编译时出现error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory的错误,所以需要提前解决

解决方法为创建软连接

  1. find / -name libssl.so.1.1

  2. ln -s /usr/local/lib/libssl.so.1.1 /usr/lib/libssl.so.1.1

  3. ln -s /usr/local/lib/libcrypto.so.1.1 /usr/lib/libcrypto.so.1.1

然后在make install时会报错找不到zlib模块,安装zlib模块

dpkg -i zlib1g-dev_xxxxxxxx.deb

然后进行编译

make&&make install 

安装完成之后提示

WARNING: The script easy_install-3.9 is installed in '/usr/local/python3/bin' 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: The scripts pip3 and pip3.9 are installed in '/usr/local/python3/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

提示我们安装的脚本不在路径中,下面创建链接。

创建python3.8的软链接

rm /usr/bin/python3

ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3

rm /usr/bin/pip3

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

        rm的原因是因为本身ubuntu16包含python3.5版本,所以需要把之前的软链接删除后再重新进行链接。

添加环境变量

打开/etc/profile.d/

新建一个python3.sh文件

vim python3.sh

文件内容添加环境变量

expoer PATH=“$PATH=:/usr/local/python3/bin”

重载一下环境变量

source ../profile

至此,python3安装完毕。

批量安装python依赖库

 先升级pip库

python3 -m pip install --upgrade pip-21.3.1-xxxxx.whl

在升级pip的时候可能会出现return Command 'lsb_release -a' returned non-zero exit status 1的问题,只需要删除lsb_release文件就行。

sudo rm /usr/bin/lsb_release

批量安装python库

 pip install --no-index --find-links=./whl/ -r requirement.txt

批量安装sanic库

pip install --no-index --find-links=./whl/ -r requirement.txt

解决dpkg error proccessing package libgl1-mesa-glx问题

#dpkg --force-depends --purge libgl1-mesa-glx
#sudo apt-get -f install
dpkg --force-depends -i libgl1-mesa-glx_18.0.5-0ubuntu0_16.04.1_amd64.deb

安装一些libgl1的依赖包,如果不安装,可能会在import cv2时报错ImportError: libxxx.so.1: cannot open shared object file: No such file or directory。选择批量安装libgl1-depend文件夹中的deb文件。

dpkg --force-depends -i *.deb

全部安装完成后进入python3内核,输入import cv2、import ssl、import _ssl测试安装结果。若没有报错,则安装成功。

运行的时候可能报错, /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.22' not found。程序的编译器的版本是比较低,缺少GLIBCXX_3.4.22,其实就是少libstdc++.so.6.0.22。

mv libstdc++.so.6.0.22  /usr/lib/x86_64-linux-gnu/

  1. cd /usr/lib/x86_64-linux-gnu/

  2. rm libstdc++.so.6

  3. ln libstdc++.so.6.0.22 libstdc++.so.6

报错requests.exceptions.SSLError: HTTPSConnectionPool(host='XXX', port=443),是因为在离线情况下,paddleocr无法下载模型,需要手动将模型放到指定目录下并解压缩

det-->/.paddleocr/2.3.0.1/ocr/det/ch/
rec-->/.paddleocr/2.3.0.1/ocr/rec/ch/
mobile_v2.0_cls-->/.paddleocr/2.3.0.1/ocr/cls/

使用tar -xf xxxxxxx.tar 命令进行解压缩

记得更改tools/infer/utilify.py中的参数

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Ubuntu 18.04上离线部署PaddleOCR,可以按照以下步骤进行操作: 1.安装PaddlePaddle深度学习框架,可以参考官方文档进行安装:https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html 2.下载PaddleOCR代码,可以从GitHub上下载最新的代码:https://github.com/PaddlePaddle/PaddleOCR 3.安装PaddleOCR所需的依赖库,可以使用以下命令进行安装: ```shell sudo apt-get update sudo apt-get install -y libgl1-mesa-glx libglib2.0-0 libsm6 libxrender1 libxext6 libfontconfig1 ``` 4.下载PaddleOCR所需的模型文件,可以从PaddleOCR的官方网站上下载:https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_det_train.tar、https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_server_v2.0_rec_infer.tar、https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar、https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar、https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar 5.解压缩模型文件,可以使用以下命令进行解压缩: ```shell tar -xvf ch_ppocr_server_v2.0_det_train.tar tar -xvf ch_ppocr_server_v2.0_rec_infer.tar tar -xvf ch_ppocr_mobile_v2.0_cls_infer.tar tar -xvf ch_ppocr_mobile_v2.0_det_infer.tar tar -xvf ch_ppocr_mobile_v2.0_rec_infer.tar ``` 6.安装PaddleOCR,可以使用以下命令进行安装: ```shell cd PaddleOCR pip install -r requirements.txt python setup.py install ``` 7.测试PaddleOCR是否安装成功,可以使用以下命令进行测试: ```shell python tools/infer/predict_system.py --image_dir="./doc/imgs_en/11.jpg" --det_model_dir="./inference/ch_ppocr_server_v2.0_det_train" --rec_model_dir="./inference/ch_ppocr_server_v2.0_rec_infer" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer" ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值