用pyinstaller打包代码后,提示no module named 'tools',在代码前面加了路径也不行,安装了tools之后还是提示没有这个模块,请教下这是python版本和pyinstaller的兼容性问题吗?
调试是用的pycharm下面创建的环境,py3.8。贴个图,这个是打包之后的运行结果。
这个是运行的代码前端,这段代码在py环境下可以正常运行并得到结果,但是打包之后就会提示No module name tools
#import os
# model must content 'model' and 'params' files
from paddleocr import PaddleOCR, draw_ocr
import sys,os
base_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(base_path)
def str_ocr(Pic_Name):
runpath = os.path.abspath(".")
img_path = runpath + '/' + Pic_Name
ocr = PaddleOCR(
det_model_dir=runpath + "/det/",
rec_model_dir=runpath + '/rec/',
rec_char_dict_path=runpath + '/rec/dict.txt',
cls=False,
cls_image_shape='3, 48, 192',
cls_model_dir=runpath + '/cls',
cls_thresh=0.9,
det=True,
det_algorithm='DB',
det_db_box_thresh=0.5,
det_db_thresh=0.3,
det_db_unclip_ratio=2.0,
det_east_cover_thresh=0.1,
det_east_nms_thresh=0.2,
det_east_score_thresh=0.8,
det_max_side_len=960,
enable_mkldnn=False,
gpu_mem=8000,
image_dir=None,
ir_optim=True,
label_list=['0', '180'],
lang='ch',
max_text_length=25,
rec=True,
rec_algorithm='CRNN',
rec_batch_num=30,
rec_char_type='ch',
rec_image_shape='3, 32, 320',
use_angle_cls=True,
use_gpu=False,
use_pdserving=False,
use_space_char=True,
use_tensorrt=False,
use_zero_copy_run=False,
# def myocr(img_path):
result = ocr.ocr(img_path)
print(result)
# return result
for line in result:
print('识别结果:', line)
print('X坐标为:', line[0][0])
print('Y坐标为:', line[0][2])
print('识别到的文字是:', line[1][0])
print('准确度为:', line[1][1])
return result
str_ocr("screen.bmp")
# 显示结果
# from PIL import Image
# image = Image.open(img_path).convert('RGB')
# im_show = draw_ocr(image, result, txts=None, scores=None, font_path='/path/to/PaddleOCR/doc/simfang.ttf')
# im_show = Image.fromarray(im_show)
# im_show.save('result.jpg')