Azure Automation中BlobServiceClient导入报错求助
解决Azure Automation中Python 3.8导入azure-storage-blob的错误
可能原因及解决步骤
1. 确认依赖包是否正确安装
- 登录Azure门户进入你的Automation账户,查看模块列表,确认
azure-storage-blob已存在且版本为12.20.0。 - 若不存在或版本不符:
- 删除现有旧版本的
azure-storage-blob模块。 - 重新添加模块:选择从PyPI安装,指定版本
12.20.0,等待安装完成。
- 删除现有旧版本的
2. 排查版本冲突
Azure Automation可能预安装了旧版azure-storage包(非azure-storage-blob),导致导入冲突。可在代码开头添加版本检查:
import sys from importlib.metadata import version try: print("azure-storage-blob 版本:", version("azure-storage-blob")) except ImportError: print("azure-storage-blob 未安装")
运行后若显示版本不是12.20.0,需手动上传指定版本的wheel包:
- 本地执行命令下载独立wheel包:
pip download azure-storage-blob==12.20.0 --no-deps - 回到Azure Automation模块页面,点击添加模块,选择本地下载的
.whl文件上传安装。
3. 验证依赖兼容性
azure-storage-blob 12.20.0依赖特定版本的azure-core、cryptography等包,若Automation中这些包版本不兼容,也会导致导入失败。可:
- 确认
azure-storage-blob 12.20.0的官方依赖清单,匹配所需依赖包版本。 - 手动上传对应版本的依赖包到Automation模块,确保版本适配。
4. 测试基础导入
编写极简测试代码验证环境:
from azure.storage.blob import BlobServiceClient print("导入成功")
若仍失败,尝试重启Automation账户的Python运行时,或检查是否有其他自定义模块干扰。
内容的提问来源于stack exchange,提问作者Bandaru Prudhvi
相关产品推荐
相关产品推荐

