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

部署Flask应用至Azure App Service遇No module named 'azure'问题求助

解决Flask+Azure Key Vault部署依赖错误问题

我尝试把一个简单Flask应用部署到Linux环境的Azure App Service,应用功能是接收用户输入的密钥,从Azure Key Vault中检索对应值。

应用代码

from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential

初始requirements.txt配置

azure-mgmt-resource
Flask==2.0.2
azure-identity==1.10.0
azure-keyvault-secrets==4.6.0

遇到的错误

运行时提示:python 3.10.10 - No module named 'azure',尝试添加azure包后触发以下错误:

│ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-x2lo6n9j/azure_e4ab6d93138d4411b0a31c7f2ffe6ad2/setup.py", line 60, in <module>
          raise RuntimeError(message)
      RuntimeError:
      
      Starting with v5.0.0, the 'azure' meta-package is deprecated and cannot be installed anymore.
      Please install the service specific packages prefixed by `azure` needed for your application.
      
      The complete list of available packages can be found at:
      https://aka.ms/azsdk/python/all
      
      Here's a non-exhaustive list of common packages:
      
      -  azure-mgmt-compute (https://pypi.python.org/pypi/azure-mgmt-compute) : Management of Virtual Machines, etc.
      -  azure-mgmt-storage (https://pypi.python.org/pypi/azure-mgmt-storage) : Management of storage accounts.
      -  azure-mgmt-resource (https://pypi.python.org/pypi/azure-mgmt-resource) : Generic package about Azure Resource Management (ARM)
      -  azure-keyvault-secrets (https://pypi.python.org/pypi/azure-keyvault-secrets) : Access to secrets in Key Vault
      -  azure-storage-blob (https://pypi.python.org/pypi/azure-storage-blob) : Access to blobs in storage accounts
      
      A more comprehensive discussion of the rationale for this decision can be found in the following issue:
      https://github.com/Azure/azure-sdk-for-python/issues/10646
      
      
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
##[error]Bash exited with code '1'.

Azure Pipeline安装依赖脚本

- script: |
      python -m venv env
      source env/bin/activate
      python -m pip install --upgrade pip
      python -m pip install -r requirements.txt
    displayName: 'Install dependencies'

解决方案

  • 核心原因:azure元包已被官方废弃,无法安装;初始requirements.txt中的特定服务包已经满足需求,出现No module named 'azure'是因为虚拟环境未正确生效或依赖安装不完整。
  • 具体修复步骤:
    1. 还原requirements.txt到初始配置,绝对不要添加azure包,你已经包含了所需的azure-identity、azure-keyvault-secrets等特定服务包。
    2. 优化Pipeline脚本,增加环境验证步骤,确保使用虚拟环境内的工具:
      - script: |
          python -m venv env
          source env/bin/activate
          echo "Using Python: $(which python)"
          echo "Using pip: $(which pip)"
          python -m pip install --upgrade pip
          python -m pip install --no-cache-dir -r requirements.txt
        displayName: 'Install dependencies'
      
    3. 启用--no-cache-dir参数避免缓存导致的依赖安装异常。
    4. 确认Azure App Service的Python运行时版本为3.10.10,与本地开发环境保持一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 23:32:05