【问题标题】:Can't use Matplotlib with Python installed by Conda on Mac无法在 Mac 上由 Conda 安装的 Python 使用 Matplotlib
【发布时间】:2017-02-25 06:35:32
【问题描述】:

我无法让 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 安装:

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 列表:

#
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() 

请帮帮我!!

【问题讨论】:

    标签: python-2.7 matplotlib anaconda osx-elcapitan conda


    【解决方案1】:

    我终于解决了!!我会删除这个问题,但我希望这个答案对像我这样的其他初学者有用。

    基本答案是in this answer 但作为初学者我不明白如何找到文件并实施解决方案。这么笨很尴尬,但我正在学习和努力,所以请原谅我。这是初学者版本,一步一步。

    正如另一个答案所说“在那里创建一个文件 ~/.matplotlib/matplotlibrc 并添加以下代码:后端:TkAgg”

    在我的情况下,该文件存在,但我不知道如何找到它。有一个 python 命令

    matplotlib.matplotlib_fname()
    

    然后只需将后端从我的“macosx”更改为“TkAgg”(保存并退出文件)。

    然后我需要在 python 解释器工作之前重新启动它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2019-11-13
      • 2011-05-04
      • 1970-01-01
      • 2020-04-30
      相关资源
      最近更新 更多