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

Python中导入BlobServiceClient遇ModuleNotFoundError问题求助

问题:导入BlobServiceClient时触发ModuleNotFoundError

我想要在Python代码中使用BlobServiceClient类,但无论怎么尝试,运行代码时都会抛出ModuleNotFoundError。

已执行的操作

  • 已执行安装命令:pip install azure-storage-blob
  • 尝试过两种导入语句:
    from azure.storage.blob.aio import BlobServiceClient
    from azure.storage.blob import BlobServiceClient
    

当前环境版本详情

包名称版本号
Python3.9.7
azure-common1.1.28
azure-core1.26.4
azure-eventgrid4.10.0
azure-identity1.12.0
azure-keyvault4.2.0
azure-keyvault-certificates4.7.0
azure-keyvault-keys4.8.0
azure-keyvault-secrets4.7.0
azure-servicebus7.9.0
azure-storage-blob12.16.0
azure-storage-common2.1.0
azure-storage-file2.1.0
azure-storage-file-share12.12.0

解决方法

1. 确认Python环境一致性

检查运行脚本的Python解释器和执行pip install的是否为同一个环境:

# 查看pip关联的Python版本
pip --version
# 查看当前脚本使用的Python版本
python --version

如果版本不一致,使用对应环境的pip重新安装包,比如python3 -m pip install azure-storage-blob,或激活虚拟环境后操作。

2. 卸载冲突的旧版SDK包

你安装的azure-storage-common(2.1.0)和azure-storage-file(2.1.0)属于Azure Storage旧版SDK,会和新版azure-storage-blob(12.x)产生依赖冲突,执行以下命令卸载:

pip uninstall azure-storage-common azure-storage-file -y

之后重新升级安装新版包:

pip install --upgrade azure-storage-blob

3. 验证包安装路径

确认azure-storage-blob的安装目录在Python的搜索路径中:

import sys
print(sys.path)

同时用pip show azure-storage-blob查看包的安装位置,如果不在搜索路径中,可手动添加路径或重新安装到正确位置。

4. 检查虚拟环境状态

如果使用了虚拟环境,确保运行脚本前已激活对应的环境,避免包安装到全局环境但脚本使用虚拟环境的情况。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 16:33:12