【问题标题】:Importing pytorch in Spyder crashes kernel after installing matplotlib安装 matplotlib 后在 Spyder 中导入 pytorch 会导致内核崩溃
【发布时间】:2019-04-02 12:45:21
【问题描述】:

我在 Anaconda3 中创建了一个环境,并在 Linux 机器上安装了 pytorch 和 spyder。以下是规格:

spyder                    3.3.1  
ipython                   7.0.1  
python                    3.7.0  
pytorch                   0.4.1  
torchvision               0.2.1  

当我打开 spyder 并导入 torch 时,它可以工作。之后我安装了 matplotlib 3.0.1。重新启动 spyder 并再次导入 pytorch 会在 spyder 的 ipython 窗口上显示一条消息:

An error ocurred while starting the kernel
terminate called after throwing an instance of 'std::runtime_error'
what(): expected ) but found 'ident' here:
aten::_addmv(Tensor self, Tensor mat, Tensor vec, *, Scalar beta=1, Scalar alpha=1) ‑> Tensor
~~~~~~ <‑‑‑ HERE

在 bash 终端上,我收到消息:

js: Not allowed to load local resource:   
file:///home/user/anaconda3/envs/myenv/lib/python3.7/site-packages/spyder/utils/help/static/css/default.css 

几个月来我一直在另一个环境中使用所有这些包(所以它们是旧版本),所以它一定是新版本的东西。
如果我在终端上运行 ipython 或 python,导入工作,所以我得出结论它与 spyder 有关。

“解决方案”很明显:安装旧版本的软件包,但还有其他更可持续的解决方案吗?

【问题讨论】:

    标签: python matplotlib anaconda spyder pytorch


    【解决方案1】:

    我有 ipython 7.0.1 和 matplotlib 2.0.2 和同样的问题,似乎 ipython 在以下两个命令后崩溃:%matplotlib auto 后跟 import torch

    当两个命令位于单独的块中时,这在 spyder 和 jupyter notebook 中都会发生。

    对我有用的是: 首先确保 spyders 后端图形设置为内联: 工具 -> 首选项 -> IPython 控制台 -> 支持内联的图形。 然后import torch 然后使用%matplotlib auto 从内联切换到外部绘图。

    请注意,这不会再发生 ipython 7.2.0 和 matplotlib 3.0.2

    【讨论】:

    • 我确认 PyTorch 1.3.1 和 Matplotlib 3.1.2 存在这个问题。我的默认图形是 QT5。我切换到内联,这个问题就解决了。
    猜你喜欢
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2016-11-29
    • 1970-01-01
    • 2022-10-05
    • 2017-08-14
    相关资源
    最近更新 更多