You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure函数应用中pdf2text无法正常工作问题求助

解决Azure函数应用中textract无法调用pdf2txt.py的问题

问题场景

使用textract编写了读取PDF内容的脚本,本地运行正常,但部署到Azure函数应用后报错,提示pdf2txt.py未安装。虽然requirements.txt中已添加textract和pdf2text,但依赖未正确生效。

脚本代码

import textract
import tempfile

def read_file(bytes):
    with tempfile.NamedTemporaryFile('wb', delete=True) as temp:
        temp.write(bytes)
        temp.flush()
        context = textract.process(temp.name, encoding='utf-8',extension=".pdf")
    
    return context.decode('utf-8')

错误信息

pdf2txt.py /tmp/tmpe3yo9gax` failed because the executable
`pdf2txt.py` is not installed on your system. Please make
sure the appropriate dependencies are installed before using
textract:

    http://textract.readthedocs.org/en/latest/installation.html

解决方案

  • 修正依赖包名称:pip中的pdf2text并非textract处理PDF所需的依赖,textract实际依赖的是pdfminer.six。修改requirements.txt,将pdf2text替换为pdfminer.six,内容如下:

    textract
    pdfminer.six
    
  • 指定PDF处理方法:在调用textract.process时显式指定method='pdfminer',强制textract使用pdfminer.six提供的工具,避免自动查找错误的可执行文件。修改后的代码片段:

    context = textract.process(temp.name, encoding='utf-8', extension=".pdf", method='pdfminer')
    
  • 清理缓存重新部署:删除Azure函数应用的旧部署包,重新触发部署,确保新的依赖包被正确安装。

内容的提问来源于stack exchange,提问作者Jeroen Vermunt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 20:40:13