matplotlib安装问题

本文介绍了如何解决使用Python3.x时遇到的GTK3Agg后端绘图错误,提供了详细的错误信息及解决步骤。推荐安装cairocffi库来规避此问题,并给出了具体的安装命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

画图时出现错误:

/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py:18: UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi.
  "The Gtk3Agg backend is known to not work on Python 3.x with pycairo. "
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 69, in on_draw_event
    buf, cairo.FORMAT_ARGB32, width, height)
NotImplementedError: Surface.create_for_data: Not Implemented yet.
/usr/local/lib/python3.4/dist-packages/matplotlib/backends/backend_gtk3.py:215: Warning: Source ID 7 was not found when attempting to remove it
  GLib.source_remove(self._idle_event_id)
解决方法:

解决方案:
正如你所看到的,所以给出的建议是:cairocffi很简单的安装指南。如果满足依赖关系*那么简单:*逻辑应该的依赖关系:

原文:

As you can see:

"The Gtk3Agg backend is known to not work on Python 3.x with pycairo."

And so the suggestion presented is:

Try installing cairocffi.

The installation guide for cairocffi is pretty straight-forward. If the dependencies* are met it is as simple as:

pip install cairocffi

*The dependencies for Py3 should logically be:

sudo apt-get install python3-dev
sudo apt-get install libffi-dev

其中,在安装libffi-dev要求安装libffi6的固定版本,即出现一下错误:

libffi-dev : Depends: libffi6 (= 3.1~rc1+r3.0.13-12) but 3.1~rc1+r3.0.13-12ubuntu0.1 is to be installed

通过如下方法安装指定版本:

sudo apt-cache policy libffi6

sudfo apt-get install libffi6=3.1~rc1+r3.0.13-12

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值