1、泣血经验1.使用python 3.6-3.9都是没有问题的,下面我们就来说一说关于python编辑器怎么安装第三方库?我们一起去了解并探讨一下这个问题吧!

python编辑器怎么安装第三方库(安装Python第三方库paddleocr的踩坑历程)

python编辑器怎么安装第三方库

1、泣血经验

1.使用python 3.6-3.9都是没有问题的

2.pip升级不升级也是没有问题的

3.尽量不要看人家的经验,有时候经验会害死你。

4.熟读paddleocr的官方安装及测试过程

2、安装过程:

安装paddle。这个安装就按百度官网的来,不要验证是不是安装正确,只要不报错就正确,因为网上有一个验证的方法老是过不去,卡了好长时间,其实随着paddle的升级,验证方法也会改变。

#执行以下命令安装(推荐使用百度源)

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

#或

python -m pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple

git clone paddleOCR项目,这个项目其实就是在百度飞桨的基础上研发的一个套件而已。

#推荐

git clone https://github.com/PaddlePaddle/PaddleOCR

#因为网络问题无法pull成功,也可选择使用码云上的托管, 码云托管代码可能无法实时同步本github项目更新,存在3~5天延时,请优先使用推荐方式

git clone https://gitee.com/paddlepaddle/PaddleOCR

下载后安装

cd PaddleOCR

python -m pip install -r requirments.txt

这个时候就是最艰苦的时候,有各种各样的问题,有的说要安装C build tool。有的说要下载shapely。各种各样的问题。经过测试,问题整理如下。

既然是使用requirments.txt 安装,我们看一下requirments.txt到底是什么

shapely

scikit-image==0.17.2

imgaug==0.4.0

pyclipper

lmdb

tqdm

numpy

visualdl

python-Levenshtein

opencv-contrib-python==4.4.0.46

lxml

premailer

openpyxl

其实就是要安装的一下依赖,不仅shapely, 其他的这些依赖都有可能安装失败。所以一个最保险的方法就是shapely先安装一下。然后再运行命令,看哪个没有安装好,再下载再安装

里面的依赖在这个网站都能找到。https://www.lfd.uci.edu/~gohlke/pythonlibs/

如果找不到私信我。

依据shapely为例。安装方法如下:

pip install Shapely-1.7.1-cp37-cp37m-win_amd64.whl

像下面的问题,就是python-Levenshtein 没有安装好。千万不要想着去安装十几个G的 VC

ERROR: Command errored out with exit status 1:

command: 'f:\python3.7\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-r6rqf3id\\python-levenshtein_572ba2d684844e8da173c059cf96014d\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-r6rqf3id\\python-levenshtein_572ba2d684844e8da173c059cf96014d\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-zf7tpan2\install-record.txt' --single-version-externally-managed --compile --install-headers 'f:\python3.7\Include\python-Levenshtein'

cwd: C:\Users\ADMINI~1\AppData\Local\Temp\pip-install-r6rqf3id\python-levenshtein_572ba2d684844e8da173c059cf96014d\

Complete output (27 lines):

running install

running build

running build_py

creating build

creating build\lib.win-amd64-3.7

creating build\lib.win-amd64-3.7\Levenshtein

copying Levenshtein\StringMatcher.py -> build\lib.win-amd64-3.7\Levenshtein

copying Levenshtein\__init__.py -> build\lib.win-amd64-3.7\Levenshtein

running egg_info

writing python_Levenshtein.egg-info\PKG-INFO

writing dependency_links to python_Levenshtein.egg-info\dependency_links.txt

writing entry points to python_Levenshtein.egg-info\entry_points.txt

writing namespace_packages to python_Levenshtein.egg-info\namespace_packages.txt

writing requirements to python_Levenshtein.egg-info\requires.txt

writing top-level names to python_Levenshtein.egg-info\top_level.txt

reading manifest file 'python_Levenshtein.egg-info\SOURCES.txt'

reading manifest template 'MANIFEST.in'

warning: no previously-included files matching '*pyc' found anywhere in distribution

warning: no previously-included files matching '*so' found anywhere in distribution

warning: no previously-included files matching '.project' found anywhere in distribution

warning: no previously-included files matching '.pydevproject' found anywhere in distribution

writing manifest file 'python_Levenshtein.egg-info\SOURCES.txt'

copying Levenshtein\_levenshtein.c -> build\lib.win-amd64-3.7\Levenshtein

copying Levenshtein\_levenshtein.h -> build\lib.win-amd64-3.7\Levenshtein

running build_ext

building 'Levenshtein._levenshtein' extension

error: Microsoft Visual C 14.0 is required. Get it with "Microsoft Visual C Build Tools": https://visualstudio.microsoft.com/downloads/

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

ERROR: Command errored out with exit status 1: 'f:\python3.7\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-r6rqf3id\\python-levenshtein_572ba2d684844e8da173c059cf96014d\\setup.py'"'"'; __file__='"'"'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\pip-install-r6rqf3id\\python-levenshtein_572ba2d684844e8da173c059cf96014d\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\ADMINI~1\AppData\Local\Temp\pip-record-zf7tpan2\install-record.txt' --single-version-externally-managed --compile --install-headers 'f:\python3.7\Include\python-Levenshtein' Check the logs for full command output.

3 文字识别

这个时候千万不要看别人的经验,一定要看gitee官网上面的示例。因为别人的经验可能是上一个版本的,这个版本不行了。先下载三个模型,按照示例走即可,

这里如果你在windows上下载后解压会丢失东西,这个地方要在linux或者mac 下解压的。切记切记

mkdir inference && cd inference

# 下载超轻量级中文OCR模型的检测模型并解压

wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar && tar xf ch_ppocr_mobile_v2.0_det_infer.tar

# 下载超轻量级中文OCR模型的识别模型并解压

wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar && tar xf ch_ppocr_mobile_v2.0_rec_infer.tar

# 下载超轻量级中文OCR模型的文本方向分类器模型并解压

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

cd ..

解压完毕后应有如下文件结构:

├── ch_ppocr_mobile_v2.0_cls_infer

│ ├── inference.pdiparams

│ ├── inference.pdiparams.info

│ └── inference.pdmodel

├── ch_ppocr_mobile_v2.0_det_infer

│ ├── inference.pdiparams

│ ├── inference.pdiparams.info

│ └── inference.pdmodel

├── ch_ppocr_mobile_v2.0_rec_infer

├── inference.pdiparams

├── inference.pdiparams.info

└── inference.pdmodel

运行检测命令

# 预测image_dir指定的单张图像

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/" --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True

# 预测image_dir指定的图像集合

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/" --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True

# 如果想使用CPU进行预测,需设置use_gpu参数为False

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/" --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False

,