运行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
相关产品推荐
相关产品推荐

