2016-01-24 56 views
3

此問題已在herehere之間提出。但是,解決方案並沒有解決我的問題。matplotlib:RuntimeError:Python未作爲框架安裝

原來的錯誤是,當我嘗試import matplotlib.pyplot,我得到:

Traceback (most recent call last): File "", line 1, in File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/init.py", line 32, in pylab_setup globals(),locals(),[backend_name],0) File "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in from matplotlib.backends import _macosx RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

我也跟着解決方案添加~/.matplotlib/matplotlibrc文件的代碼:backend: TkAgg。這樣做後,我的錯誤改爲:

/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') objc[25120]: Class TKApplication is implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[25120]: Class TKMenu is implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[25120]: Class TKContentView is implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined. objc[25120]: Class TKWindow is implemented in both /Users/XX/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.

我不知道如何解決這個問題。我沒有使用虛擬機。你可以幫幫我嗎?謝謝!

PS:我發現,通過添加:

import matplotlib
matplotlib.use('TkAgg')

import matplotlib.pyplot之前,它似乎工作。但是每次添加這兩行代碼都很煩人......有人知道發生了什麼,我該如何解決它?謝謝!

+0

我與你類似的情況。 (我在Mac OS X上,使用anaconda python,「TkAgg」後端,錯誤信息是一樣的)當我運行腳本時,它只是崩潰。 –

回答

11

我在virtualenv中運行我的腳本。 Python版本是3.5。

添加一行:

backend: TkAgg 
文件

~/.matplotlib/matplotlibrc 

這解決了這個問題。

+1

沒有爲python 2.7工作 – Sibish