我无法让Matplotlib工作并收到以下错误......
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/nltk/probability.py", line 1794, in plot
from matplotlib import pylab
File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/pylab.py", line 274, in <module>
from matplotlib.pyplot import *
File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/Users/<my_profile>/Documents/Dev/AnacondaInstall/anaconda/envs/snowflakes/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
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
我正在运行OSX 10.11.5
Conda信息是......
目前的conda安装:
platform : osx-64
conda version : 4.2.9
conda is private : False
conda-env version : 4.2.9
conda-build version : 1.21.3
python version : 2.7.12.final.0
conda list:
#
babel 2.3.3 py27_0
cycler 0.10.0 <pip>
**matplotlib 1.5.3 <pip>**
nltk 3.2.1 <pip>
numpy 1.11.2 <pip>
oauthlib 1.1.2 <pip>
openssl 1.0.2h 1
pip 8.1.2 py27_0
pyparsing 2.1.10 <pip>
python 2.7.12 1
python-dateutil 2.5.3 <pip>
pytz 2016.6.1 py27_0
readline 6.2 2
requests 2.10.0 <pip>
requests-oauthlib 0.6.2 <pip>
setuptools 23.0.0 py27_0
simplejson 3.8.2 <pip>
six 1.10.0 <pip>
sqlite 3.13.0 0
tk 8.5.18 0
tweepy 3.5.0 <pip>
twython 3.4.0 <pip>
wheel 0.29.0 py27_0
zlib 1.2.8 3
我正在运行python(使用Anaconda),然后添加以下内容......
import nltk
from nltk import FreqDist
from nltk import bigrams
from __future__ import print_function
from matplotlib import *
from nltk.book import *
cfd = nltk.ConditionalFreqDist(
(target, fileid[:4])
for fileid in inaugural.fileids()
for w in inaugural.words(fileid)
for target in ['america', 'citizen']
if w.lower().startswith(target))
以下内容返回错误...
cfd.plot()
请帮帮我!!
答案 0 :(得分:2)
我终于解决了!!我会删除这个问题,但我希望这个答案对像我这样的其他初学者来说很有用。
基本答案是in this answer ,但作为初学者,我不明白如何找到文件并实施解决方案。令人尴尬的是这样一个numpty但我正在学习和努力所以请原谅我。这是初学者版本,一步一步。
正如另一个答案所说“在那里创建一个文件〜/ .matplotlib / matplotlibrc并添加以下代码:backend:TkAgg”
在我的情况下文件存在,但我不知道如何找到它。有一个python命令
matplotlib.matplotlib_fname()
然后,只需将后端从我的情况下的'macosx'更改为'TkAgg'(保存并退出文件)。
然后我需要在它运行之前重启python解释器。