matplotlib:RuntimeError:Python未作为框架安装 [英] matplotlib: RuntimeError: Python is not installed as a framework

查看:199
本文介绍了matplotlib:RuntimeError:Python未作为框架安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题曾在此处(也是

This question has been asked before, in here, also here. However, the solution didn't fix the problem for my case.

最初的错误是,当我尝试import matplotlib.pyplot时,我得到了:

The original error is, when I try to import matplotlib.pyplot, I got:

回溯(最近一次通话最近):文件",第1行,在 文件 "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", 第114行,在 _backend_mod,new_figure_manager,draw_if_interactive,_show = pylab_setup()文件 "/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/init.py", pylab_setup中的第32行 globals(),locals(),[backend_name],0)文件"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", 第24行,在 从matplotlib.backends导入_macosx RuntimeError:未作为框架安装Python. Mac OS X后端将无法 如果未将Python安装为框架,则可以正常运行.见 Python文档以获取有关将Python作为插件安装的更多信息 Mac OS X上的框架.请重新安装Python作为框架, 或尝试其他后端之一.如果您正在使用Matplotlib 在虚拟环境中,请参阅在虚拟环境中使用Matplotlib Matplotlib常见问题解答中的环境"

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

我按照解决方案添加了一个代码为backend: TkAgg~/.matplotlib/matplotlibrc文件.完成此操作后,我的错误更改为:

I followed the solutions to add a ~/.matplotlib/matplotlibrc file with the code: backend: TkAgg. After doing that, my error changed to:

/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273: 用户警告:Matplotlib正在使用fc-list构建字体缓存.这 可能需要一点时间. warnings.warn('Matplotlib正在构建字体 使用fc-list缓存.这可能需要一点时间.')objc [25120]:类 TKApplication都在这两个版本中实现 /Users/XX/anaconda/lib/libtk8.5.dylib和 /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk.中的一个 将使用两个.哪一个是未定义的. objc [25120]:类TKMenu是 在/Users/XX/anaconda/lib/libtk8.5.dylib和 /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk.中的一个 将使用两个.哪一个是未定义的. objc [25120]:类别 TKContentView都在这两者中实现 /Users/XX/anaconda/lib/libtk8.5.dylib和 /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk.中的一个 将使用两个.哪一个是未定义的. objc [25120]:类别TKWindow 在/Users/XX/anaconda/lib/libtk8.5.dylib和 /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk.中的一个 将使用两个.哪个是未定义的.

/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.

我不知道该如何解决.我没有使用虚拟机.你可以帮帮我吗?谢谢!

I have no idea how to fix that. I'm not using a virtual machine. Could you help me? Thank you!

PS:我发现是通过添加:

PS: I found out that by adding:

导入matplotlib
matplotlib.use('TkAgg')

import matplotlib
matplotlib.use('TkAgg')

import matplotlib.pyplot之前,它似乎起作用.但是每次都添加这两行代码很烦人.有人知道发生了什么,如何解决?谢谢!

before import matplotlib.pyplot, it seems to work. But adding those two lines of codes every time is annoying... Does anyone know what's going on and how I can fix it? Thank you!

推荐答案

我在virtualenv中运行脚本. Python版本是3.5.

I run my script in virtualenv. Python version is 3.5.

添加一行:

backend: TkAgg

在文件中:

~/.matplotlib/matplotlibrc

这解决了问题.

如果您想进一步了解为什么添加此功能可以解决此问题,则可以阅读自定义matplotlib的后端.而 TkAgg 解决了此问题,因为它与Tkinter具有依赖性.

If you want to know more about why adding this solves the problem, you can read about customizing matplotlib's backend. And TkAgg solves this issue because of it's dependency with Tkinter.

这篇关于matplotlib:RuntimeError:Python未作为框架安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆