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

PyCharm导入BaseBlobService报错,Databricks却正常运行求助

解决ModuleNotFoundError: No module named 'azure.storage.blob.baseblobservice'

问题根源

Databricks环境默认安装的是旧版azure-storage-blob(v2.x及以下),这个版本保留了BaseBlobService类;而你在PyCharm中安装的是新版azure-storage-blob(v12.x及以上),新版已彻底移除该类,改用全新的API架构。

两种解决方案

方案1:降级到兼容旧API的版本

在PyCharm的终端执行以下命令,安装和Databricks环境一致的旧版包:

pip install azure-storage-blob==2.1.0

安装完成后即可正常使用from azure.storage.blob.baseblobservice import BaseBlobService。

方案2:改用新版API(推荐)

新版azure-storage-blob使用BlobServiceClient替代BaseBlobService,API设计更简洁且持续维护,示例代码如下:

from azure.storage.blob import BlobServiceClient

# 初始化Blob服务客户端
connection_string = "你的Azure存储账户连接字符串"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# 示例:列出所有存储容器
for container in blob_service_client.list_containers():
    print(container.name)

额外提示

如果需要PyCharm和Databricks环境代码通用,建议统一升级Databricks中的azure-storage-blob版本到v12+,旧版包已停止维护,存在潜在安全隐患。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 03:54:10