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

Python 3.12运行Azure Functions报错,寻求解决方案

解决方案

核心问题

Azure Functions 当前工具链暂不支持 Python 3.12,必须切换到你本机已安装的 Python 3.9 环境来运行。

具体操作步骤

1. 创建并激活 Python 3.9 的虚拟环境

如果还没为 Python 3.9 创建虚拟环境,先执行以下命令:

# 根据系统环境,调用对应版本的 Python 3.9 执行创建命令
# Windows 可能是 python3.9,Mac/Linux 直接用 python3.9
python3.9 -m venv .venv_39

然后激活虚拟环境:

  • Windows(PowerShell):.\.venv_39\Scripts\Activate.ps1
  • Windows(CMD):.\.venv_39\Scripts\activate.bat
  • Mac/Linux:source .venv_39/bin/activate

2. 配置 Azure Functions 工具指向 Python 3.9

激活 3.9 虚拟环境后,执行命令让 func 工具识别到正确的 Python 路径:

func settings set PYTHON_PATH "<你的3.9虚拟环境Python路径>"

示例路径:

  • Windows:.\.venv_39\Scripts\python.exe
  • Mac/Linux:./.venv_39/bin/python

3. 重新安装依赖

在激活的 3.9 虚拟环境中,重新安装 Azure Functions 相关依赖:

pip install -r requirements.txt

4. 启动 Azure Functions

现在执行启动命令即可正常运行:

func host start

额外注意事项

  • 切换 VS Code 的 Python 解释器:点击左下角状态栏的 Python 版本,选择 .venv_39 对应的解释器,确保编辑器环境与运行环境一致
  • 暂不要使用 Python 3.12 环境运行 Azure Functions,需等待官方工具链更新支持该版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 16:50:57