已安装sagemaker仍报错ModuleNotFoundError: No module named 'sagemaker.huggingface'
问题成因
通过conda install sagemaker安装的SageMaker SDK包不包含huggingface子模块。Conda渠道提供的SageMaker包属于精简版本,未集成Hugging Face相关扩展模块,而pip官方源的SageMaker SDK才完整包含该子模块。
解决步骤
- 卸载当前conda环境中的sagemaker包:
conda remove sagemaker -y
- 使用pip重新安装指定版本的完整SageMaker SDK:
pip install sagemaker==2.213.0
- 验证子模块是否存在:
运行以下代码确认:
import sagemaker if 'huggingface' in dir(sagemaker): print('The huggingface submodule is included in this version of sagemaker.') else: print('The huggingface submodule is not included in this version of sagemaker.')
此时应输出包含子模块的提示。
4. 重新导入模块:
from sagemaker.huggingface import HuggingFace
额外说明
若使用SageMaker Studio的SageMaker Distribution环境,可直接使用预安装的完整SageMaker SDK,无需自行创建conda环境。若必须使用自定义conda环境,务必通过pip安装sagemaker而非conda渠道。
内容的提问来源于stack exchange,提问作者Yann Stoneman
相关产品推荐
相关产品推荐

