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

已安装pooch仍报错:scipy.datasets调用ascent提示缺失依赖

已安装pooch但scipy.datasets仍提示缺少依赖的解决办法

问题现象

运行以下代码时,pip show pooch显示pooch 1.7.0已成功安装,但调用scipy.datasets.ascent()时抛出ImportError,提示缺少可选依赖pooch:

import scipy.datasets
import pooch
!pip show pooch
ascent = scipy.datasets.ascent()
ascent.shape

报错详情:

Name: pooch
Version: 1.7.0
Summary: "Pooch manages your Python library's sample data files: it automatically downloads and stores them in a local directory, with support for versioning and corruption checks."
Home-page: https://github.com/fatiando/pooch
Author: The Pooch Developers
Author-email: fatiandoaterra@protonmail.com
License: BSD 3-Clause License
Location: /usr/local/lib/python3.11/site-packages
Requires: packaging, platformdirs, requests
Required-by: 
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[17], line 4
      2 import pooch
      3 get_ipython().system('pip show pooch')
----> 4 ascent = scipy.datasets.ascent()
      5 ascent.shape

File /usr/local/lib/python3.11/site-packages/scipy/datasets/_fetchers.py:71, in ascent()
     66 import pickle
     68 # The file will be downloaded automatically the first time this is run,
     69 # returning the path to the downloaded file. Afterwards, Pooch finds
     70 # it in the local cache and doesn't repeat the download.
---> 71 fname = fetch_data("ascent.dat")
     72 # Now we just need to load it with our standard Python tools.
     73 with open(fname, 'rb') as f:

File /usr/local/lib/python3.11/site-packages/scipy/datasets/_fetchers.py:27, in fetch_data(dataset_name, data_fetcher)
     25 def fetch_data(dataset_name, data_fetcher=data_fetcher):
     26     if data_fetcher is None:
---> 27         raise ImportError("Missing optional dependency 'pooch' required "
     28                           "for scipy.datasets module. Please use pip or "
     29                           "conda to install 'pooch'.")
     30     # The "fetch" method returns the full path to the downloaded data file.
     31     return data_fetcher.fetch(dataset_name)

ImportError: Missing optional dependency 'pooch' required for scipy.datasets module. Please use pip or conda to install 'pooch'.

解决步骤

  • 检查Python环境一致性
    Jupyter Notebook使用的Python内核可能和pip安装pooch的环境不一致。先在Notebook中运行以下代码确认当前Python路径:

    import sys
    print(sys.executable)
    

    然后用该路径的pip重新安装pooch:

    !{sys.executable} -m pip install pooch
    
  • 升级scipy到最新稳定版
    部分旧版本scipy对pooch的版本检测或导入逻辑存在问题,升级scipy可解决兼容性问题:

    !pip install --upgrade scipy
    
  • 重启Jupyter Kernel
    如果是在安装pooch之后才启动的Kernel,模块导入缓存可能未刷新,重启Kernel后重新运行代码即可。

  • 手动指定data_fetcher(兜底方案)
    若以上方法无效,可手动初始化pooch实例并传给scipy的数据集函数:

    import scipy.datasets
    from scipy.datasets._fetchers import _get_pooch
    
    # 手动获取pooch实例
    data_fetcher = _get_pooch()
    # 传入ascent函数
    ascent = scipy.datasets.ascent(data_fetcher=data_fetcher)
    print(ascent.shape)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 09:16:05