python matplotlib 画图show()不显示图

我的环境是centos6.3默认有个python2.6,自己又装了个python2.7版本,
matplotlib 使用show()无法显示,从网上各种查找问题,发现自带的python2.6版本可以显示图片,
但新python2.7不可以显示



1. 确保是在Linux的桌面环境下运行而不是从纯终端或ssh客户端
2. plt.show()依赖一个图形环境, 如tk, wxpython等, 要先安装一个

装了个wxpython
yum install epel-release
yum clean all
yum install wxPython

#vim simple_plot.py
from pylab import *
plot([1,2,3])
show()


[root@testserver4 ~]# python simple_plot.py --verbose-helpful
$HOME=/root
matplotlib data path /usr/local/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-linux-x86_64.egg/matplotlib/mpl-data

*****************************************************************
You have the following UNSUPPORTED LaTeX preamble customizations:

Please do not ask for support with these customizations active.
*****************************************************************

loaded rc file /usr/local/lib/python2.7/site-packages/matplotlib-1.5.0-py2.7-linux-x86_64.egg/matplotlib/mpl-data/matplotlibrc
matplotlib version 1.5.0
verbose.level helpful
interactive is False
platform is linux2
CACHEDIR=/root/.cache/matplotlib
Using fontManager instance from /root/.cache/matplotlib/fontList.cache
backend agg version v2.2


使用源码安装matplotlib
Source install from git

Clone the main source using one of:

>git clone git://github.com/matplotlib/matplotlib.git

and build and install as usual with:

> cd matplotlib
> python setup.py install
> python setup.py build


应该是系统自带的python2.6和新装的python2.7之间哪个设置有问题,各种网上搜索,有提问的,但是没有解决的方法,
最终我使用python集成工具Anaconda解决了这个问题,安装方法参考: http://blog.csdn.net/levy_cui/article/details/51143153
# python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from pylab import *
>>> plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x7eff8d698550>]
>>> show()
图片正常显示了。

你可能感兴趣的:(python matplotlib 画图show()不显示图)