I’ve previously written a couple of blog posts about my troubles getting matplotlib to play nicely and I run into a slightly different variant today while following Sidath Asiri’s Hello World in TensorFlow tutorial.

When I ran the script using a version of Python installed via virtualenv I got the following exception:

Traceback (most recent call last):File "iris.py", line 4, in <module>from matplotlib import pyplot as pltFile "/Users/markneedham/projects/tensorflow-playground/a/lib/python3.6/site-packages/matplotlib/pyplot.py", line 116, in <module>_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()File "/Users/markneedham/projects/tensorflow-playground/a/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup[backend_name], 0)File "/Users/markneedham/projects/tensorflow-playground/a/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>from matplotlib.backends import _macosx
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.

The solution this time was actually the same as it was in my post where I described matplotlib hanging. Instead of:

from matplotlib import pyplot as plt

We need to define a different backend, like this:

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

I also learnt an even simpler way of solving the problem via this StackOverflow post. We can achieve the same outcome by creating a file at ~/.matplotlib/matplotlibrc and populating it with the following text:

$ cat ~/.matplotlib/matplotlibrc
backend: TkAgg

Now we can go back to importing matplotlib without the need to define the backend each time. Success!

Python via virtualenv on Mac OS X: RuntimeError: Python is not installed as a framework.相关推荐

  1. 在MAC OS 下配置python + Flask ,并支持pyCharm编辑器

    https://www.cnblogs.com/lgphp/p/3841098.html 在MAC OS 下配置python + Flask ,并支持pyCharm编辑器 flask是一个micro ...

  2. 自学python之路(mac升级自带Python)

    自学Python日记 今天打开自己的mac输入py -V,oh,fuck!上面一段文字提示2.7版本的python 后续可能不支持了,看来需要升级自带的Python了.我使用过Linux系统的Pyth ...

  3. Mac os + Flask + PyCharm python开发环境集成

    1. 打开mac自带终端安装virtualenv 执行 sudo easy_install virtualenv  /  sudo pip install virtualenv 2.安装完 virtu ...

  4. mac os平台使用python爬虫自动下载巨潮网络文件

    环境配置 选择python+selenium+wget+Safari的环境来下载文件,本来期望使用phantomjs,但使用时点击出的链接网页为空白网页,无法下载文件. 使用Safari时遇到的错误: ...

  5. python爬虫scrapy步骤mac系统_Mac中Python 3环境下安装scrapy的方法教程

    前言 最近抽空想学习一下python的爬虫框架scrapy,在mac下安装的时候遇到了问题,逐一解决了问题,分享一下,话不多说了,来一起看看详细的介绍吧. 步骤如下: # 在Mac上Python3环境 ...

  6. mac安装完python怎么打开-Mac OS系统如何安装python

    Mac OS安装python步骤 如果你使用苹果电脑的 Mac OS 系统,下载时,请进入 https://www.python.org/页面,选择Downloads,在弹出的菜单中选择Mac OS ...

  7. mac怎么安装python开发环境搭建_Mac OS搭建Python开发环境

    简书 Wwwwei 转载请注明原创出处,谢谢! 前言 最近在看一些关于机器学习的内容,其中大量代码需要Python的运行环境,所以搭建了Python开发环境,这里记录下,方便大家学习. 安装Pytho ...

  8. python调用窗口找到文件,使用Python在Mac OS X中查找当前活动窗口

    Is there a way to find the application name of the current active window at a given time on Mac OS X ...

  9. Python 环境搭建(Win 安装以及Mac OS 安装)

    千里之行始于足下,今天我们先来学习 Python 环境搭建. 注意:本系列教程基于 Python 3.X Python 环境搭建 Win 安装 打开 Python 官网 https://www.pyt ...

最新文章

  1. mongodb type it for more
  2. 自动装箱与自动拆箱的一些问题
  3. Singing Superstar 字符串哈希-map操作
  4. HDU 2049 不容易系列之(4)——考新郎( 错排 )
  5. 计算机考研新大纲,2020考研计算机新大纲考情分析
  6. A5.2021年全国数学建模竞赛B题-赛题分析与评阅要点(乙醇偶合制备C4烯烃分析)
  7. Struts2中访问web元素
  8. 输出毫秒_使用AMETEK直流电源实现波形变化的输出
  9. 直播卖房和VR看房,到底是噱头还是新趋势?
  10. 魔兽怀旧服服务器位置,魔兽世界怀旧服PDD在哪个服务器 魔兽世界怀旧服pdd去哪个区...
  11. 手机APP项目测试点(内容)总结
  12. 分享五款好用的PDF编辑工具
  13. 用python 把视频转换为图片
  14. STM32单线串口对总线舵机的控制
  15. 程序人生之项目团队那些人与事(1)
  16. Win10控制面板打不开怎么办?
  17. 2020年Android GMS 认证 boot logo 最新要求
  18. 自己搭建FRP服务器,速度不错!
  19. iframe相关,iframe样式
  20. 几种技巧,帮你提升接口查询速度

热门文章

  1. 揪出造成失败用户登录的应用主机名、数据库用户信息
  2. 定义在计算机中怎么翻译,Profile在计算机中翻译成什么
  3. wampserver mysql乱码_ajax +json +php提交mysql数据库 中文乱码(wamp server 本地测试)求解?...
  4. rabbitmq direct 多个消费者_RabbitMQ从零开始
  5. 仿手环运动app的html,连接手环.html
  6. avs3 ts格式封装 标准_超能课堂(204):多媒体容器格式变迁录
  7. 实现企业级分布式储存之mogilefs和fastdfs的应用
  8. c# HttpWebResponse 调用WebApi
  9. 端口扩展器技术让网络交换焕然一新
  10. 2016软考网络规划设计师论文写作