【问题标题】:"RuntimeError: Could not create write struct" with pyplot“运行时错误:无法创建写入结构”与 pyplot
【发布时间】:2018-08-01 17:18:18
【问题描述】:

更新:

无论我尝试绘制什么,我都会收到此消息:即使是这样

plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

返回错误RuntimeError: Could not create write struct


我正在尝试内联绘制原始图像。我的 Jupyter 笔记本在带有端口转发功能的 AWS 实例上运行。

我的代码如下:

见上文更新

当我尝试这个时,我收到下面的错误消息,最终出现消息RuntimeError: Could not create write struct

奇怪的是,完全相同的代码在本地运行良好。我可以整天查看图像。

因此,作为一个实验,我从 AWS 上下载了图像并在本地运行它,我可以看到它显示得很好。

我在想,我的 Matplotlib 甚至 jupyter 笔记本肯定有问题。

我已在多种配置中多次删除/重新安装。我确保软件包的本地版本和 AMI 版本完全相同。

我不知道发生了什么。

错误本身自然是没有用的。而且在谷歌上搜索错误时,几乎没有精确的字符串匹配结果,这总是很可怕。

其他随机的东西:

我使用的是 Python 2.7
这两个库都在 Conda 中进行管理
木星:4.4.0 Matplotlib:2.1.2

<matplotlib.image.AxesImage at 0x7f261c1f2b50>
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    332                 pass
    333             else:
--> 334                 return printer(obj)
    335             # Finally look for special method names
    336             method = get_real_method(obj, self.print_method)

/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in <lambda>(fig)
    238 
    239     if 'png' in formats:
--> 240         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    241     if 'retina' in formats or 'png2x' in formats:
    242         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt, bbox_inches, **kwargs)
    122 
    123     bytes_io = BytesIO()
--> 124     fig.canvas.print_figure(bytes_io, **kw)
    125     data = bytes_io.getvalue()
    126     if fmt == 'svg':

/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2214                     orientation=orientation,
   2215                     dryrun=True,
-> 2216                     **kwargs)
   2217                 renderer = self.figure._cachedRenderer
   2218                 bbox_inches = self.figure.get_tightbbox(renderer)

/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    524         try:
    525             _png.write_png(renderer._renderer, filename_or_obj,
--> 526                            self.figure.dpi, metadata=metadata)
    527         finally:
    528             if close:

RuntimeError: Could not create write struct

<matplotlib.figure.Figure at 0x7f2624b94950>

【问题讨论】:

  • 你的虚拟机磁盘/内存不足吗?
  • 不...我的 AWS 实例有一吨
  • 你能画出基本的折线图吗?显示正常(例如.png)图像?
  • 请看我的更新
  • 可以查看stackoverflow.com/a/39538968/194586 或那里的其他答案

标签: python-2.7 matplotlib imshow


【解决方案1】:

这不清楚,我也不知道为什么,但是我删除了 matplotlib 的 conda 安装,然后用 pip 重新安装了 matplotlib。

现在一切正常。

¯\_(ツ)_/¯

【讨论】:

    猜你喜欢
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2012-11-02
    • 1970-01-01
    相关资源
    最近更新 更多