【发布时间】:2020-03-04 15:20:37
【问题描述】:
我正在尝试在也具有 OCR 功能的 Google App Engine 上部署一个应用程序。我使用自制软件下载了 tesseract,并使用pytesseract 包装在 Python 中。 OCR 功能在我的本地系统上工作,但在我将应用程序上传到 Google App Engine 时它不起作用。
我从 usr/local/cellar/tesseract 复制了 tesseract 文件夹并粘贴到我的应用程序的工作目录中。我将 tesseract 文件和 pytesseract 文件上传到了应用引擎。我已经用os.getcwd() 指定了tesseract 的路径,以便pytesseract 可以找到它。然而,这不起作用。应用引擎找不到要执行的文件,因为它们不在同一个目录中 (os.getcwd())。
pytesseract.py 中的代码
cmda = os.getcwd()
# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
def find_all(name, path):
result = []
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
return result
founds = find_all("tesseract",cmda)
tesseract_cmd = founds[0]
来自 Google App Engine 的错误是:
tesseract 未安装在您的路径上。
【问题讨论】:
-
您能否检查一下您是否在 requirements.txt 中指定了 tesseract 依赖项?你可以看到一个例子here。这是用于在 Python 中指定依赖项的documentation。
-
您是否尝试在应用启动代码中打印
os.getcwd()?它可能不是你所期望的那样。也许试试os.chdir()你的tesseract在哪里? -
它们都不起作用。有人知道如何在 gcloud 应用引擎中添加路径吗?
-
我也可以添加路径,还是不行。有没有办法在应用引擎上安装只能通过 brew 获得的包?
标签: python python-3.x google-app-engine gcloud python-tesseract