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

运行Semantic Kernel练习时遇ImportError:无法从services导入Service

Semantic Kernel练习中ImportError问题解决

问题详情

在完成Microsoft的Semantic Kernel练习时,执行代码from services import Service触发以下错误:

ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from services import Service
      3 # Select a service to use for this notebook (available services: OpenAI, AzureOpenAI, HuggingFace)
      4 selectedService = Service.OpenAI

ImportError: cannot import name 'Service' from 'services' (c:\Users\xxx\AppData\Local\Programs\Python\Python312\Lib\site-packages\services\__init__.py)

经排查,PyPI上的services库是旧版本,并非练习所需的微软专属本地模块。

解决步骤

  • 卸载PyPI上的services库,避免干扰:
    pip uninstall -y services
    
  • 确认当前Notebook的工作目录为Semantic Kernel仓库的python/notebooks路径,练习中的services.py是该目录下的本地文件,不是PyPI包。
  • 检查工作路径,确保Python能优先加载同目录下的services.py,而非site-packages中的旧库。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 05:43:13