【问题标题】:Python via Conda on Mac OS X: RuntimeError: Python is not installed as a framework在 Mac OS X 上通过 Conda 使用 Python:RuntimeError:Python 未作为框架安装
【发布时间】:2020-01-27 13:07:53
【问题描述】:

我在 Mac 10.14.6 上运行,到目前为止我尝试过的所有解决方案都没有奏效。我正在关注OpenAI spinningup 的文档并被困在这一行:

python -m spinup.run plot data/installtest/installtest_s0

在尝试导入 matplotlib 并绘制一些图表时,我不断得到:

文件 /anaconda3/envs/spinningup2/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", 第 14 行,在 from matplotlib.backends import _macosx ImportError: Python 未作为框架安装。 Mac OS X 后端将无法 如果 Python 未作为框架安装,则可以正常运行。见 Python 文档,了解有关将 Python 安装为 Mac OS X 上的框架。请重新安装 Python 作为框架, 或尝试其他后端之一。如果您使用的是 (Ana)Conda,请 安装 python.app 并将 'python' 的使用替换为 'pythonw'。看 Matplotlib 常见问题解答中的“在 OSX 上使用 Matplotlib”了解更多信息 信息。

在网上搜索后,我发现 这是一个很常见的问题,所以这是我迄今为止尝试过的:


1. https://github.com/scikit-optimize/scikit-optimize/issues/637

添加

import matplotlib
matplotlib.use('PS')

在导入matplotlib.pyplot之前

我仍然有同样的错误。


2. https://markhneedham.com/blog/2018/05/04/python-runtime-error-osx-matplotlib-not-installed-as-framework-mac/

我用的不是from matplotlib import pyplot as plt

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

但是我仍然遇到同样的错误。


3. matplotlib: RuntimeError: Python is not installed as a framework

添加一行:

backend: TkAgg

在文件中:

~/.matplotlib/matplotlibrc

这并不能解决我的问题,我也有同样的错误


4.

我尝试在 ~/.matplotlib/matplotlibrc 创建一个文件并用以下文本填充它:

$ cat ~/.matplotlib/matplotlibrc
backend: TkAgg

当使用cat 命令时,这会以某种方式使我的 MAC 崩溃并导致重新启动。我很困惑。


任何帮助或建议将不胜感激。我已经尝试了我在这个网站上找到的所有建议,但都没有成功。

【问题讨论】:

  • 您是否在终端中运行脚本?如果是这样,请使用pythonw 而不是python
  • 我正在关注官方文档,但没有提及使用pythonw。您建议更改命令 python -m spinup.run plot data/installtest/installtest_s0 吗?我看到错误消息中写的内容,但不确定如何在不出现新错误消息的情况下替换 python 的使用。
  • 我建议使用pythonw,我不知道您的脚本是做什么的,但是当我在终端中运行使用matplotlib 的脚本时遇到了同样的错误。当我改用pythonw 时,问题得到了解决。
  • Tk 现在在 mac os 上有某种可怕的错误。试试QT5:matplotlib.use('Qt5Agg')
  • 另外,macOS 后端的处理将在更新的 matplotlibs 中更新,因此您不再需要使用pythonw,但我忘记了该版本的 matplotlib 是否已发布或即将发布.无论如何,请让我们知道您尝试使用的 matplotlib 版本。

标签: python python-3.x macos matplotlib


【解决方案1】:

我能够通过卸载 matplotlib,然后使用 Conda 重新安装我需要的确切版本(可能是 3.0.3)来解决该问题。

我还注意到,Conda 安装了六个 (six-1.15.0-py37hecd8cb5_0) 作为其中的一部分,所以不确定罪魁祸首是什么,但现在已修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 2017-01-16
    相关资源
    最近更新 更多