无法在Google Colab上导入paddleocr库。

huangapple go评论83阅读模式
英文:

Not able to import paddleocr library on Google Colab

问题

我无法在成功安装了paddlepaddle和paddleocr之后,在Google Colab上导入paddleocr库。它出现了如下错误:

**from paddleocr import PaddleOCR, draw_ocr**



错误无法导入paddle核心因为存在以下文件/usr/local/lib/python3.10/dist-packages/paddle/fluid/libpaddle.so
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-e16532d3d475> in <cell line: 1>()
----> 1 from paddleocr import PaddleOCR, draw_ocr
      2 import os
      3 import cv2
      4 import matplotlib.pyplot as plt
      5 get_ipython().run_line_magic('matplotlib', 'inline')

8 frames
/usr/local/lib/python3.10/dist-packages/paddle/fluid/core.py in <module>
    267 
    268 try:
--> 269     from . import libpaddle
    270 
    271     if avx_supported() and not libpaddle.is_compiled_with_avx():

ImportError: libssl.so.1.1: 无法打开共享对象文件没有那个文件或目录

之前一切正常,但今天我无法导入paddleOCR。感谢社区对此问题的帮助。

英文:

I am not able to import paddleocr library on Google Colab after the install of paddlepaddle and paddleocr successfully. It hits the error as shown below:

**from paddleocr import PaddleOCR, draw_ocr**



Error: Can not import paddle core while this file exists: /usr/local/lib/python3.10/dist-packages/paddle/fluid/libpaddle.so
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-e16532d3d475> in <cell line: 1>()
----> 1 from paddleocr import PaddleOCR, draw_ocr
      2 import os
      3 import cv2
      4 import matplotlib.pyplot as plt
      5 get_ipython().run_line_magic('matplotlib', 'inline')

8 frames
/usr/local/lib/python3.10/dist-packages/paddle/fluid/core.py in <module>
    267 
    268 try:
--> 269     from . import libpaddle
    270 
    271     if avx_supported() and not libpaddle.is_compiled_with_avx():

ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory

Previously, everything was okay but I am not able to import paddleOCR today. Appreciate the community help on this issue.

答案1

得分: 0

使用以下步骤,我成功在Google Colab中运行了PaddleOCR:

  1. 转到"Runtime"选项卡,选择"Change runtime type",在"Hardware accelerator"下选择"GPU"。

  2. 在Google Colab的content部分上传要分析的图像。

  3. 使用pip下载PaddleOCR模块:

!pip install paddlepaddle-gpu
!pip install paddleocr
  1. 使用Bash下载libssl1.1
!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
!sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
  1. 从GitHub克隆PaddleOCR存储库以使用字体:
!git clone https://github.com/PaddlePaddle/PaddleOCR
  1. 运行代码块来测试PaddleOCR是否正常工作。代码块来自PaddleOCR的pypi页面中的项目描述部分:
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from IPython import display

img_path = '/content/test_img.PNG'
ocr = PaddleOCR(lang='en')
result = ocr.ocr(img_path, rec=False)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

result = result[0]
image = Image.open(img_path).convert('RGB')
im_show = draw_ocr(image, result, txts=None, scores=None, font_path='/content/PaddleOCR/StyleText/fonts/ko_standard.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
display.Image('result.jpg')

输出如下:
无法在Google Colab上导入paddleocr库。

英文:

Using the following steps, I was able to get PaddleOCR to run in Google Colab:

  1. Go the the "Runtime" tab, select "Change runtime type" and under "Hardware accelerator" select "GPU".

  2. Upload the image to be analyzed in the content section of Google Colab.

  3. Download the PaddleOCR modules using pip:

!pip install paddlepaddle-gpu
!pip install paddleocr
  1. Download libssl1.1 using Bash:
!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
!sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
  1. Clone the PaddleOCR repo from GitHub to use the fonts:

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

  1. Run a codeblock to test that PaddleOCR is working. The codeblock is from the project description section on PaddleOCR's pypi page:
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from IPython import display

img_path = '/content/test_img.PNG'
ocr = PaddleOCR(lang='en')
result = ocr.ocr(img_path,rec=False)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)

result = result[0]
image = Image.open(img_path).convert('RGB')
im_show = draw_ocr(image, result, txts=None, scores=None, font_path='/content/PaddleOCR/StyleText/fonts/ko_standard.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
display.Image('result.jpg')

The output is below:
无法在Google Colab上导入paddleocr库。

huangapple
  • 本文由 发表于 2023年7月20日 17:24:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定