gpt4 book ai didi

python : OSError: [Errno 2] No such file or directory

转载 作者:太空狗 更新时间:2023-10-29 19:34:38 25 4
gpt4 key购买 nike

我正在使用 pytesseract 库从图像中提取文本。当我在本地主机上运行代码时,这工作正常。但是当我在 openshift 上部署时出现上述错误。

下面是我到目前为止编写的代码。

try:
import Image
except ImportError:
from PIL import Image
import pytesseract
filePath = PATH_WHERE_FILE_IS_LOCATED # '/var/lib/openshift/555.../app-root/data/data/y.jpg'
text = pytesseract.image_to_string(Image.open(filePath)) # this line produces error

上述错误的回溯是

>>> pytesseract.image_to_string(Image.open(filePath))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/var/lib/openshift/56faaee42d527151d5000089/app- root/runtime/repo/pytesseract/pytesseract.py", line 132, in image_to_string
boxes=boxes)
File "/var/lib/openshift/56faaee42d527151d5000089/app-root/runtime/repo/pytesseract/pytesseract.py", line 73, in run_tesseract
stderr=subprocess.PIPE)
File "/opt/rh/python27/root/usr/lib64/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/opt/rh/python27/root/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

但是 Image.open(filePath) 返回对象引用

 <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=1366x768 at 0x7FC5A9F719D0>

如何消除这个错误?提前致谢!!

最佳答案

要么您没有在“openshift”上安装 tesseract-ocr,要么它不在您的 PATH 中。参见 https://pypi.python.org/pypi/pytesseract/0.1检查您是否可以从命令行执行 tesseract 命令。

关于 python : OSError: [Errno 2] No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36625207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com