首页 > 解决方案 > 带有 osx 后端的 Matplotlib 3.0

问题描述

我从这里使用 Miniconda 在 macOS 10.14 上安装了 Python 3.7 。我的工作流程使用 iPython 运行使用 Matplotlib 生成绘图的脚本。在我的 iPython 配置文件ipython_config.py中,我有以下设置可以在 Mac 上正确渲染图形窗口:

c.InteractiveShellApp.gui = 'osx'
c.InteractiveShellApp.matplotlib = 'osx'

当我在终端中运行 iPython 时,出现以下错误:

ImportError:Python 未作为框架安装。如果没有将 Python 作为框架安装,Mac OS X 后端将无法正常运行。有关在 Mac OS X 上将 Python 作为框架安装的更多信息,请参阅 Python 文档。请重新安装 Python 作为框架,或尝试使用其他后端之一。如果您使用的是 (Ana)Conda,请安装 python.app 并将“python”的使用替换为“pythonw”。有关更多信息,请参阅 Matplotlib 常见问题解答中的“在 OSX 上使用 Matplotlib”。

使用 Matplotlib 2.2.3 时我没有收到此错误。

Matplotlib 3.0文档pythonw指出,使用 Conda 和 Matplotlib 时需要Python 的框架构建(称为)。我用conda install python.app. 然后文档说使用pythonw而不是python. 但是我如何告诉 iPython 使用pythonw呢?

标签: pythonpython-3.xmatplotlibipythonconda

解决方案


打字

echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc

在为我固定 IPython 的终端中。


推荐阅读