【问题标题】:Anaconda Runtime Error: Python is not installed as a framework?Anaconda 运行时错误:Python 未作为框架安装?
【发布时间】:2015-10-01 02:45:39
【问题描述】:

我已经使用 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.

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

【问题讨论】:

  • 我想你的问题在stackoverflow.com/questions/4130355/…得到了回答
  • 这篇文章让我陷入了困境,但它让我遇到了使用 Homebrew、Macports 和其他软件产生的冲突。我不得不编辑我的 bash_profile——之前使用过 Homebrew 和 MacPorts,我的 $PATH 声明是冲突的。删除这些条目后,matplot lib 工作正常。我确定我在一些旧代码中的某个地方破坏了某些东西,但 Anaconda 似乎是我一直追求的 Python 的实现。

标签: python macos matplotlib anaconda


【解决方案1】:

如果您遇到此错误,请不要忘记检查您的 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

【讨论】:

  • 对于 Anaconda,.bash_profile 应具有以下内容:export PATH="/Users/username/anaconda/bin:$PATH"
【解决方案2】:

如果在 virtualenv 中使用,我建议按照此处的说明进行操作: http://matplotlib.org/faq/virtualenv_faq.html

【讨论】:

  • 很好的说明。即使在 virtualenv 中,来自其他安装的冲突可能仍然存在。如果遇到我提到的问题,请务必检查 .bash_profile 中的 $PATH 声明
【解决方案3】:

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

pip install matplotlib==1.4.3

【讨论】:

  • Glen,安装旧版本的库可能已经为您解决了这个问题,但是 mac ports/Homebrew 设置的冲突 PATH 是导致我出错的原因。从那以后,我在 envs 上投入了更多的精力
  • 也适用于 OSX 10.11 El Capitan
  • 在 Catalina 上工作
【解决方案4】:

如果只是matplotlib的问题,换后端试试:

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

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

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

【讨论】:

【解决方案5】:

我在使用 anaconda 2 和 matplotlib 1.5.3 时遇到了同样的问题。

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

【讨论】:

    【解决方案6】:

    使用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.

    【讨论】:

      【解决方案7】:

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

      如果你使用 pip 安装:

      1. 创建~/.matplotlib/matplotlibrc

      2. 将“backend: TkAgg”(不带引号)添加到文件中。

      【讨论】:

      • 如果我使用的是 conda 环境,这对我有用,但如果我使用的是 virtualenv 环境,则不行。
      • 至少对我来说,当 matplotlib 安装了 conda 而不仅仅是 pip 时,这也有效。
      • 为什么matplotlib 不自动执行此操作?
      • 为了后代,有人可以解释一下更改“后端”的作用以及“作为框架”安装 Python 意味着什么?奇怪的是,我在网上找不到任何简洁的答案。
      【解决方案8】:

      重新安装 matplotlib 应该可以为您解决问题,就像它为我解决的问题一样

      conda 安装 matplotlib

      【讨论】:

      • 在这种情况下,这不是解决方案。我们负责来自 MacPorts 和 homebrew 的冲突路径声明。
      【解决方案9】:

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

      例如 pythonw testFile.py.

      【讨论】:

      • 你能解释一下有什么区别吗?
      • 注意:这篇文章的标签中有macos。我认为在不同的环境下运行是使用 pythonw 运行脚本的解决方案,尽管不是促进 python 素养的答案。
      【解决方案10】:

      来自matplotlib documentation

      $ conda install python.app

      你需要一个用于 matplotlib 的 Python 框架构建,但是

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

      注意我必须添加 conda-forge 频道,因为 python.app 不包含在默认的 miniconda 频道中

      $ conda config --add channels conda-forge

      【讨论】:

        猜你喜欢
        • 2016-04-19
        • 2016-04-30
        • 1970-01-01
        • 1970-01-01
        • 2017-11-26
        • 2023-02-19
        • 2015-09-01
        • 1970-01-01
        • 2018-06-20
        相关资源
        最近更新 更多