python 安装matplotlib
2014-05-06 20:29
246 查看
Ubuntu安装Matplotlib
ubuntu下安装matplotlib的复杂度远远比windows下复杂的多,相对双击就能解决问题的,现在你需要时不时的解决编译带来的各种问题。
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了:
>>> import numpy
>>> print numpy.version.version
1.6.1
>>> import matplotlib
>>> print matplotlib.__version__
0.99.3
到此,基本搞定。接下里,运行个Sample试试看。
?
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:
import matplotlib 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()
相关文章推荐
- 【python】matplotlib在windows下安装
- 【python】matplotlib在windows10 和win7下安装
- windows 安装python3.6(numpy,scipy,pandas,matplotlib,scikit-learn)
- python环境下安装matplotlib
- windows下安装python库matplotlib
- Win7,64位下Python3.5.2,安装numpy、matplotlib、scipy(whl文件)
- windows环境下python2.7、pycharm、numpy_mkl、scipy、sklearn、Matplotlib、jupyter完整安装教程
- 安装Python的画图工具matplotlib
- python及相关模块库的安装教程,例如pygame,Numpy, Scipy, matplotlib和scikit-learn等模块sklearn库
- 雾山的Python学习笔记---Matplotlib的安装
- Ubuntu-Python2.7安装 scipy,numpy,matplotlib
- win32 python3.4.1 下安装Numpy、matplotlib、Scipy、theano、sklearn
- pip 安装 Python的matplotlib
- 用python画柱状图以及numpy和matplotlib的安装及配置
- 在Windows上安装Python以及Numpy、Matplotlib等模块
- Windows64 系Python、NumPy与matplotlib 安装方法
- python 安装matplotlib后运行图表时提示错误numpy版本不对的解决方法
- Python 模块--matplotlib安装和学习
- 64位 win7,Python3.5.0下安装numpy,matplotlib,scipy
- python matplotlib 安装 和错误处理