python - 带有 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
呢?
解决方案
打字
echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc
在为我固定 IPython 的终端中。
推荐阅读
- node.js - 为什么我的sql多行插入查询包含语法错误?
- javascript - 相同的代码在不同的机器上生成不同的快照
- javascript - jQuery - 如何通过动态表中的文本框显示下拉选择的值
- ubuntu - 使用智能卡 pcks11 的电子应用程序和 HTTPS/SSL 身份验证
- c# - 从 sqlite 返回的 C# 序列化 DataTable 结果正在返回 XML 格式
- android-studio - 当我启动 android 应用程序时,我可以在 logcat 中看到警告并终止应用程序
- c++ - 可以在基于范围的 for 循环中使用模板化的开始/结束方法吗
- sql-server - 为什么我的 SQL Server 差异备份有时会失败?
- google-apps-script - 应用程序在提醒类型的日历中添加事件
- mysql - MySQL:如果存在则选择最新记录,如果不存在则为 NULL