import matplotlib 因 DLL 加载错误而失败,但仅在 spyder 中

import matplotlib fails with DLL load error but only in spyder

我正在使用 miniconda。 Spyder安装在基础环境中,配置spyder_kernels指向我工作环境中的解释器py37。那是安装 numpy、pandas 和 matplotlib 的地方。

当我在命令提示符下激活 py37 并在那里使用 python 时,我可以在我的脚本中毫无意外地使用 matplotlib。

当我尝试从 spyder 运行 相同的脚本时,出现此 DLL 导入错误:

File "C:\Users\eli\miniconda3\envs\py37\lib\site-packages\matplotlib\__init__.py", line 190, in _check_versions
        from . import ft2font

ImportError: DLL load failed: The specified module could not be found.

谁能告诉我如何进一步诊断这个问题?它似乎正在尝试从正确的环境中导入。 import numpyimport pandas 可以工作(两者都只安装在 py37 中,而不是 base)。这是基地环境的某种干扰吗?我知道我可以在 py37 环境中安装 spyder,但我喜欢 spyder-kernels 的想法,因为它会使工作环境更简单......如果我能让它工作的话。

看来这个问题需要升级 Spyder 和 Spyder-kernel side and/or 在 Windows side 上设置一个环境变量。

在 Spyder side 上,发布候选版本 (4.0.0rc2) 有了改进,最新 python 和 spyder-kernels > 1.8。这些必须从 spyder-ide 频道安装。

然后对我来说它仍然不起作用,因为旧的 DLL 搜索路径问题。我必须设置这个环境变量,它从 Anaconda 的搜索路径中取出一个系统目录:

CONDA_DLL_SEARCH_MODIFICATION_ENABLE to 1

在我的系统上,我认为只尝试后一个更改可能会很有趣。

感谢spyder开发者。这需要多次迭代。