Anaconda运行时错误:Python未作为框架安装?

时间:2015-07-12 22:23:37

标签: python macos matplotlib anaconda

我已经使用pkg安装程序安装了Anaconda:

Python 2.7.10 |Continuum Analytics, Inc.| (default, May 28 2015, 17:04:42) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org

但是当我尝试使用matplotlib中的任何东西时,即:

 from matplotlib import pyplot as plt

我得到了

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.

我真的不确定这意味着什么,或者如何解决它。

10 个答案:

答案 0 :(得分:42)

发布,因为我刚遇到这个问题,这是一个快速修复:

如果您使用pip进行安装:

  1. 创建~/.matplotlib/matplotlibrc

  2. 添加" backend: TkAgg" (不带引号)到文件。

答案 1 :(得分:32)

我和anaconda 2& matplotlib 1.5.3。

运行一个简单的conda install matplotlib重新安装matplotlib对我来说很有用。

答案 2 :(得分:16)

如果问题只是matplotlib,那么值得尝试更改后端:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

plt.plot([1, 2, 3], [4, 5, 6])
plt.show()

如果可行,您可以从matplotlibrc文件中永久更改后端。

答案 3 :(得分:7)

使用pythonw代替python运行文件。 这是因为python没有作为框架安装。 因此,请使用pythonw myScript.py代替python myScript.py 我相信这会解决它。

我有类似的错误。 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 using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

答案 4 :(得分:6)

我遇到了同样的问题。安装旧版本的matplotlib对我来说很有用。在虚拟环境中,在终端中尝试使用此命令:

pip install matplotlib==1.4.3

答案 5 :(得分:2)

来自matplotlib documentation

$ conda install python.app

您需要为matplotlib构建Python框架,但是

  

(Ana)conda中提供的默认python不是框架版本。但是,可以在主环境和conda envs中轻松安装框架构建:安装python.app(conda install python.app)并使用pythonw而不是python

NB我必须添加conda-forge频道,因为python.app未包含在默认的迷你康达频道中

$ conda config --add channels conda-forge

答案 6 :(得分:0)

如果您遇到此错误,请不要忘记检查您的bash_profile。

您可以通过以下方式在终端中执行此操作:

cd

然后

nano .bash_profile

检查内容。 Macports和Homebrew为他们在这里完成的事情添加了自己的标题。您可以删除它们对$ PATH的声明。离开Anaconda制作的那个。我有一个如果你想,你可以:

cp .bash_profile ./bash_profile_backup_yyyy_mm_dd 

并备份该文件,文件名索引到您更改它的日期。也就是说,只要您实际输入日期而不仅仅是我建议的格式字符。

source ~/.bash_profile

会刷新系统对bash_profile的引用,你应该很好地导入和使用matplotlib

答案 7 :(得分:0)

如果在virtualenv中使用,我建议按照以下说明操作: http://matplotlib.org/faq/virtualenv_faq.html

答案 8 :(得分:0)

重新安装matplotlib应该为你解决问题,就像它为我做的那样

conda install matplotlib

答案 9 :(得分:0)

Quickfix:使用pythonw而不是python运行文件。

例如pythonw testFile.py。