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

本地运行Watson Machine Learning时遇ImportError问题求助

Windows本地VSCode虚拟环境对接Watson Machine Learning遇ImportError问题

问题描述

在Windows本地VSCode的虚拟环境中运行Jupyter Notebook,尝试对接Watson Machine Learning时失败。已执行以下安装命令:

!pip install tensorflow
!pip install ibm_watson_machine_learning

已在Notebook中成功创建并训练Keras模型,确认tensorflow可正常运行,但执行初始化Watson ML客户端代码时:

from ibm_watson_machine_learning import APIClient

LOCATION = 'https://us-south.ml.cloud.ibm.com'
API_KEY = 'xxx-this-is-my-api-key-xxx'


wml_credentials = {
    "apikey": API_KEY,
    "url": LOCATION
}

wml_client = APIClient(wml_credentials)

触发如下错误:

ImportError: The system lacks installations of pyspark, scikit-learn, pandas, xgboost, mlpipelinepy, ibmsparkpipeline and tensorflow. At least one of the libraries is required for the repository-client to be used

解决方法

  1. 重新升级tensorflow
    尽管已安装tensorflow,但可能存在版本兼容或虚拟环境识别问题,执行升级命令确保库在当前环境中正常加载:

    !pip install --upgrade tensorflow
    
  2. 安装任意指定依赖库
    错误提示要求至少安装列表中的一个库,若升级tensorflow无效,可选择安装常用的pandas或scikit-learn:

    # 安装pandas
    !pip install pandas
    # 或安装scikit-learn
    !pip install scikit-learn
    
  3. 重启Notebook内核
    依赖库安装完成后,重启Jupyter Notebook的内核,再重新运行初始化APIClient的代码即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 14:35:53