1
<code>sudo apt-get install python-dev</code>
先安裝numpy:
2
<code>python setup.py build</code>
<code>sudo python setup.py install --prefix=/usr/local</code>
之後開始安裝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
解決方法:sudo apt-get install libfreetype6-dev
3. src/backend_agg.cpp:3:17: fatal error: png.h: no such file or
解決方法:sudo apt-get install libpng-dev
解決以上問題之後,發現可以正确編譯matplotlib了:
<code>sudo python setup.py install</code>
檢測下之前安裝的情況:
>>> import numpy
>>> print
numpy.version.version
1.6.1
>>> import matplotlib
>>>
print matplotlib.__version__
0.99.3
到此,基本搞定。接下裡,運作個sample試試看。
3
4
5
6
7
8
9
10
11
<code>from</code>
<code>pylab</code><code>import</code>
<code>*</code>
<code>t</code><code>=</code>
<code>arange(</code><code>0.0</code><code>,</code><code>2.0</code><code>,</code><code>0.01</code><code>)</code>
<code>s</code><code>=</code>
<code>sin(</code><code>2</code><code>*</code><code>pi</code><code>*</code><code>t)</code>
<code>plot(t, s, linewidth</code><code>=</code><code>1.0</code><code>)</code>
<code>xlabel(</code><code>‘time (s)‘</code><code>)</code>
<code>ylabel(</code><code>‘voltage (mv)‘</code><code>)</code>
<code>title(</code><code>‘about as simple as it gets, folks‘</code><code>)</code>
<code>grid(</code><code>true</code><code>)</code>
<code>show()</code>
終端執行: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()))
當然你如果隻想要看結果,那麼可以直接把它儲存成圖檔,用<code>savefig</code>(‘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:
期間,我按裝過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
這樣就可以了。測試: