我正在尝试在我的笔记本中运行以下单元格,但它无法请求 scipy,即使它已安装并导入到 venv 中
import seaborn as sn
import scipy
sn.clustermap(data)
抛出的错误是
venv\lib\site-packages\seaborn\matrix.py:1250, in clustermap(data, pivot_kws, method, metric, z_score, standard_scale, figsize, cbar_kws, row_cluster, col_cluster, row_linkage, col_linkage, row_colors, col_colors, mask, dendrogram_ratio, colors_ratio, cbar_pos, tree_kws, **kwargs)
1157 """
1158 Plot a matrix dataset as a hierarchically-clustered heatmap.
1159
(...)
1247
1248 """
1249 if _no_scipy:
-> 1250 raise RuntimeError("clustermap requires scipy to be available")
1252 plotter = ClusterGrid(data, pivot_kws=pivot_kws, figsize=figsize,
1253 row_colors=row_colors, col_colors=col_colors,
1254 z_score=z_score, standard_scale=standard_scale,
1255 mask=mask, dendrogram_ratio=dendrogram_ratio,
1256 colors_ratio=colors_ratio, cbar_pos=cbar_pos)
1258 return plotter.plot(metric=metric, method=method,
1259 colorbar_kws=cbar_kws,
1260 row_cluster=row_cluster, col_cluster=col_cluster,
1261 row_linkage=row_linkage, col_linkage=col_linkage,
1262 tree_kws=tree_kws, **kwargs)
RuntimeError: clustermap requires scipy to be available
你可以重新安装 scipy (在你的虚拟环境中)并重新打开你的代码编辑器(我在 VS 中使用 Jupyter),这对我有用。
import seaborn as sns
%matplotlib inline
import scipy
如果您使用 IDE,只需确保 pip install scipy