python安装matplotlib需要c编译_python 安装matplotlib

1

sudo apt-get install python-dev

先安装numpy:

1

2

python setup.py build

sudo python setup.py install --prefix=/usr/local

之后开始安装matplotlib,这下编译matplotlib就没有之前那样一帆风顺了。

1. gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory

解决方法:sudo apt-get install build-essential

2. src/ft2font.h:13:22: fatal error: ft2build.h: No such file or directory

解决方法:sudo apt-get install libfreetype6-dev

3. src/backend_agg.cpp:3:17: fatal error: png.h: No such file or directory

解决方法:sudo apt-get install libpng-dev

解决以上问题之后,发现可以正确编译matplotlib了:

1

2

python setup.py build

sudo python setup.py install

检测下之前安装的情况:

>>> import numpy

>>> print numpy.version.version

1.6.1

>>> import matplotlib

>>> print matplotlib.__version__

0.99.3

到此,基本搞定。接下里,运行个Sample试试看。

1

2

3

4

5

6

7

8

9

10

11

from pylabimport *

t= arange(0.0,2.0,0.01)

s= sin(2*pi*t)

plot(t, s, linewidth=1.0)

xlabel('time (s)')

ylabel('voltage (mV)')

title('About as simple as it gets, folks')

grid(True)

show()

终端执行:python hello.py 没有报错,也没有弹出图框。怎么回事? 我尝试把代码中每一条都手动在终端python模式下输入,结果输入show()的时候,错误提示:

Your currently selected backend, ‘agg’ does not support show().

Please select a GUI backend in your matplotlibrc file (‘/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc’)

or with matplotlib.use()

(backend, matplotlib.matplotlib_fname()))

当然你如果只想要看结果,那么可以直接把它保存成图片,用savefig(‘figure.png’)来替代前面的show()函数。但是如果要交互式的话,还需解决前面的问题。

这个问题,我找了很久,发现”this happened because your matplotlib backend is set to FltkAgg, GTK, GTKAgg, GTKCairo, TkAgg , Wx or WxAgg they required a GUI that why error occur.” To solve this you must specific other backend that not required GUI (Agg, Cairo, PS, PDF or SVG ) when use matplotlib like this in code:

importmatplotlib

matplotlib.use('Agg')

期间,我按装过Cairo,可是还是出现错误,后来发现一个比较简单的方法,用wxpython:

sudo aptitude install python-wxtools

然后在代码中使用的是matplotlib.use(‘WXAgg’)

你也可以修改/usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data目录下的matplotlibrc这个文件内容中的:

# ‘module://my_backend’

backend : WXAgg

这样就可以了。测试:

from pylab import *t= arange(0.0, 2.0, 0.01)

s= sin(2*pi*t)

plot(t, s, linewidth=1.0)

xlabel('time (s)')

ylabel('voltage (mV)')

title('About as simple as it gets, folks')

grid(True)

show()

matplotlib.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装matplotlib可能会遇到一些问题,特别是在Linux上。以下是几种可能的解决方法: 方法1:使用apt-get安装 根据引用,可以使用以下命令安装matplotlib: sudo apt-get install python3-matplotlib 请确保使用python3-matplotlib而不是python-matplotlib,因为前者适用于Python 3,而后者适用于Python 2。 方法2:使用pip3安装 如果apt-get安装方法失败,可以尝试使用pip3安装matplotlib。首先,卸载已经安装的旧版本matplotlib: sudo apt-get remove python3-matplotlib 然后,使用以下命令安装matplotlib: pip3 install matplotlib 如果下载速度比较慢,你可以尝试使用清华源来下载: pip3 install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple 方法3:使用预编译安装 如果你使用的是Jetson平台并且遇到了pip3安装失败的情况,你可以尝试使用引用提供的预编译包。首先,从https://gitee.com/PolarisF/jetson_pkgs下载适合你的版本的matplotlib编译包,例如matplotlib-3.3.4-cp36-cp36m-linux_aarch64.whl。然后,使用以下命令进行安装: pip3 install matplotlib-3.3.4-cp36-cp36m-linux_aarch64.whl 请注意,这些方法都可以安装matplotlib的最新版本,但如果你想安装其他版本,可以使用引用提供的方法。具体命令如下: export OPENBLAS_CORETYPE=ARMV8 pip3 install "matplotlib==3.3.4" 希望这些方法可以帮助你解决Linux上matplotlib安装失败的问题。如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值