PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
44.74k stars 7.86k forks source link

用apache + wsgi + jdango 部署调用PaddleOCR的程序,执行到代码“from paddleocr import PaddleOCR”时报错 #11747

Closed accsoar closed 7 months ago

accsoar commented 8 months ago

用apache + wsgi + jdango部署的web service,提供一个API来使用PaddleOCR识别图像

API涉及的代码如下(ocr识别图片的代码已移除,仅保留这句发生问题的代码“from paddleocr import PaddleOCR”):

from django.http import HttpRequest
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

import time

from paddleocr import PaddleOCR

@csrf_exempt
def recognize(request):
    print("ping() is called")

    return HttpResponse("{}",
                        content_type="application/json; encoding=utf-8",
                        status=200)
  1. 此django程序用python本地启用后(python manage.py runserver),API调用成功(ocr识别图片代码不删除的话,也可成功识别图像)。

  2. 但部署到Apache后,调用API时apache报错,报错log如下:

[Fri Mar 15 11:54:47.666727 2024] [core:notice] [pid 2116:tid 464] AH00094: Command line: 'C:\\Apache24\\bin\\httpd.exe -d C:/Apache24'
[Fri Mar 15 11:54:47.666727 2024] [mpm_winnt:notice] [pid 2116:tid 464] AH00418: Parent: Created child process 3872
[Fri Mar 15 11:54:49.104244 2024] [mpm_winnt:notice] [pid 3872:tid 484] AH00354: Child: Starting 64 worker threads.
[Fri Mar 15 11:55:55.282321 2024] [wsgi:error] [pid 3872:tid 1208] [client 10.235.59.122:59096] Error: Can not import paddle core while this file exists: C:\\Python310\\lib\\site-packages\\paddle\\base\\libpaddle.pyd\r
[Fri Mar 15 11:55:56.391697 2024] [wsgi:error] [pid 3872:tid 1208] [client 10.235.59.122:59096] Error: Can not import paddle core while this file exists: C:\\Python310\\lib\\site-packages\\paddle\\base\\libpaddle.pyd\r
[Fri Mar 15 11:55:56.860444 2024] [mpm_winnt:notice] [pid 2116:tid 464] AH00428: Parent: child process 3872 exited with status 255 -- Restarting.

但把那句from paddleocr import PaddleOCR删除的话,API调用也是成功的 (也就是说,我的Django程序在Apache中的wsgi配置应该是没问题的)

在Apache的httpd.conf文件中,wsgi相关配置如下(相关路径配置确认都没问题):

Define SRVROOT "c:/Apache24"

Listen 28886

LoadModule wsgi_module "C:/Python310/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"

WSGIPythonHome "C:/Python310"

#指定website的wsgi.py配置文件路径  
WSGIScriptAlias / C:/xxp/dj_paddleocr_test/dj_paddleocr_test/wsgi.py

#指定项目路径  
WSGIPythonPath  C:/xxp/dj_paddleocr_test

<Directory C:/xxp/dj_paddleocr_test/dj_paddleocr_test>  
    WSGIPassAuthorization On
    Options None
    AllowOverride None
    <Files wsgi.py>  
        Require all granted  
    </Files>

    # Limit HTTP methods
    <LimitExcept GET POST OPTIONS>
        Require all denied
    </LimitExcept>
</Directory>  
changdazhou commented 8 months ago

建议尝试一下使用源码安装paddleocr哈

accsoar commented 8 months ago

建议尝试一下使用源码安装paddleocr哈

就是说,直接下载paddleocr的源码?那请问如何在我的django程序中调用paddleocr来识别图像呢?有类似的示例程序吗?谢谢

changdazhou commented 8 months ago

对的,直接下载源码,使用最新的源码编译成whl包安装后再进行尝试哈