【问题标题】:import matplotlib fails with DLL load error but only in spyder导入 matplotlib 因 DLL 加载错误而失败,但仅在 spyder 中
【发布时间】:2020-03-14 05:13:08
【问题描述】:

我正在使用 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 的想法,因为它可以让工作环境更简单......如果我能让它工作的话。

【问题讨论】:

  • 标签应该是matplotlib,而不是numpy,对吧?现在,如果我没记错的话,我在 ft2font 导入时遇到了类似的问题(分别称为 dll)。我不是 100% 确定,但我认为从 Christoph Gohlke's whl files 安装 matplotlib 为我解决了这个问题,因为这与某些特定于操作系统的 dlls 有关(适用于 Linux 而非 Windows 之类的东西)。我必须说虽然我没有使用conda/miniconda,所以我不知道这是否适合你。
  • 是的,没错。

标签: matplotlib virtualenv python-import spyder


【解决方案1】:

看来此问题需要在 Spyder 和 Spyder 内核端进行升级和/或在 Windows 端设置环境变量。

在 Spyder 方面,发布候选版本 (4.0.0rc2) 有一个改进,最新的 python 和 spyder-kernels > 1.8。这些必须从 spyder-ide 通道安装。

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

CONDA_DLL_SEARCH_MODIFICATION_ENABLE to 1

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

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

【讨论】:

    猜你喜欢
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2016-01-09
    • 2011-05-03
    • 2020-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多