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

如何修复Jupyter Notebook中无法导入‘logsumexp’的错误

Fixing 'cannot import name 'logsumexp'' Error After Scikit-learn Installation

Let’s break down your problem and fix it step by step:

Root Cause

The error boils down to a version mismatch between statsmodels 0.9.0 and scipy 1.3.0:

  • Your older statsmodels version (0.9.0) expects logsumexp to live in scipy.misc, but starting from scipy 1.3.0, this function was moved to the scipy.special module. The 0.9.0 statsmodels release wasn’t updated to handle this change.
  • Upgrading/downgrading scikit-learn didn’t resolve the issue because the conflict has nothing to do with scikit-learn—it’s purely between statsmodels and scipy. Also, that sklearn 0.0 version is just a dummy meta-package; your actual working scikit-learn is 0.21.2, so that’s not a problem.

Solutions (Ordered by Recommendation)

1. Upgrade statsmodels to a compatible version

This is the cleanest, most sustainable fix. You need a statsmodels version that supports scipy 1.3.0+—aim for 0.10.0 or newer, since that’s when they adjusted the logsumexp import path. Run this command in your environment:

pip install --upgrade statsmodels

2. Downgrade scipy to match your old statsmodels

If you can’t upgrade statsmodels (e.g., due to other project dependency constraints), roll back scipy to a version where logsumexp still resides in scipy.misc. Scipy 0.19.1 works perfectly with statsmodels 0.9.0:

pip install scipy==0.19.1

3. Temporary hack (Emergency Only)

If you need a quick fix right now and can’t adjust versions, manually patch the scipy.misc module before importing statsmodels. Add these lines at the very top of your notebook:

# Patch scipy.misc to include logsumexp from scipy.special
import scipy.misc
from scipy.special import logsumexp
scipy.misc.logsumexp = logsumexp

# Now import your original libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from statsmodels.tsa.api import ExponentialSmoothing, SimpleExpSmoothing, Holt
import statsmodels.api as sm

⚠️ Note: This is a temporary workaround and might cause unexpected issues with other parts of scipy or statsmodels. Use it only if the first two solutions aren’t feasible.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 08:27:37