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

如何解决Azure HTTP函数应用本地测试的依赖包缺失问题?

问题描述

在Azure创建的HTTP函数应用,不依赖额外包时本地运行正常;添加psycopg2、azure.storage.blob、pandas等依赖后,本地测试持续报错:

ModuleNotFoundError: No module named 'psycopg2'
[2025-03-03T12:56:56.243Z] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.)

应用发布到Azure后可正常运行,但本地无法测试(需先对接本地PostgreSQL验证)。已使用虚拟环境并执行pip install -r requirements.txt安装依赖(requirements.txt包含azure-functions、azure-storage-blob、pandas、psycopg2-binary、openpyxl),但错误依旧。

解决方案
  • 确认虚拟环境已激活:启动函数前必须激活对应的虚拟环境,避免使用全局Python环境。
    • Windows:执行venv\Scripts\activate
    • Linux/macOS:执行source venv/bin/activate
  • 验证Python解释器路径:若使用VS Code,按Ctrl+Shift+P(Windows)/Cmd+Shift+P(macOS),输入Python: Select Interpreter,选择虚拟环境内的Python解释器。
  • 重装psycopg2-binary:卸载后重新安装,避免缓存或安装不完整:
    pip uninstall psycopg2-binary -y
    pip install psycopg2-binary
    
  • 检查local.settings.json配置:确保文件中FUNCTIONS_WORKER_RUNTIME值为python,且未指定错误的Python版本路径。
  • 清理本地运行缓存:删除函数根目录下的__pycache__、.azurefunctions文件夹,若存在.venv也一并删除;重新激活虚拟环境并安装依赖,再启动函数。
  • 确认requirements.txt位置:确保文件放在函数应用根目录(与host.json同层级),安装依赖时在该目录下执行pip install -r requirements.txt。

注:"No job functions found"错误通常是依赖缺失导致函数加载失败,解决psycopg2的模块问题后,该错误会自动消失。

内容的提问来源于stack exchange,提问作者Rim Benyaich

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 02:08:18