在virtualenv环境下使用matplotlib绘图时遇到了这样的问题:

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...

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 Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

似乎是因为虚拟环境与默认环境的安装配置不同造成的。

搜索错误信息之后,在STO上找到了解决方案:

1、pip安装matplotlib之后,会在根目录下产生一个.matplotlib的目录:

➜ bin ll ~/.matplotlib

我是通过cd ~/.matplotlib 进入这个文件夹的    cd ~命令是进入home目录    (就是进入home目录下的一个.matplotlib文件夹下)

total 280
-rw-r--r-- 1 me staff 78K 10 4 2015 fontList.cache
-rw-r--r-- 1 me staff 59K 1 17 15:56 fontList.py3k.cache
drwxr-xr-x 2 me staff 68B 10 4 2015 tex.cache

2、在这个目录下创建一个名为matplotlibrc的文件,内容是:

backend: TkAgg

然后保存退出,重启Python交互界面或重新运行脚本,import正常执行。

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 infor的更多相关文章

  1. 出现ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly ....的解决方法

    在terminal上运行gluoncv时遇到了一个报错问题. ImportError: Python is not installed as a framework. The Mac OS X bac ...

  2. Python标准库07 信号 (signal包,部分os包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在了解了Linux的信号基础之后,Python标准库中的signal包就很容易学习 ...

  3. Python:版本升级(Mac OS X)

    Mac OS X 10.8及以后的版本都预装了Python 2.7,但是在Mac上(Unix-like OS)上修改Python的版本并不如Windows方便.这篇文章的目标是要将Mac自带的Pyth ...

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

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

  5. 在 Mac OS X 上创建的 .NET 命令行程序访问数据库 (使用Entity Framework 7 )

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  6. 在mac os下的Apache服务器的cgi中运行python

    我是搬运工.. Running Python Programs on the Mac OS X Apache Web Server The Mac OS X operating system incl ...

  7. [转]Mac OS X framework 解析

    转载地址:http://hi.baidu.com/yonderbyron/item/9838b73472152e009cc65ec8 Mac OS X framework 解析 1.framework ...

  8. mac os去除去除.DS_Store文件--使用python和go(原创)

    .DS_Store (英文全称 Desktop Services Store)是一种由苹果公司的Mac OS X操作系统所创造的隐藏文件,目的在于存贮文件夹的自定义属性,例如文件们的图标位置或者是背景 ...

  9. Python 学习之中的一个:在Mac OS X下基于Sublime Text搭建开发平台包括numpy,scipy

    1 前言 Python有许多IDE能够用,官方自己也带了一个,Eclipse也能够. 但我在使用各种IDE之后,发现用Sublime Text是最好用的一个.因此.我都是用Sublime Text来编 ...

随机推荐

  1. AtCoder ABC 132E Hopscotch Addict

    题目链接:https://atcoder.jp/contests/abc132/tasks/abc132_e 题目大意 给定一张 N 个点 M 条边无自环无重边的一张有向图,求从起点 S 能否三步三步 ...

  2. 【工具原则】5W2H法学习笔记

    目录 问题描述 事件(原因)描述 任务描述 方案决策 小结 5W2H法又叫七问分析法,是二战中美国陆军兵器修理部首创.按事务构成要素,从规范的七个方面思考,避免疏忽遗漏. 可以应用在:问题描述.事件描 ...

  3. postgres优化项及linux上pg操作记录

    1.linux切换到pg命令: $ su - postgres $ psql postgres=# 2.查看/退出pg ps -ef |grep postgres postgres=# \q 3.一般 ...

  4. capserjs-prototype(中)

    evaluateOrDie() 具体样式: evaluateOrDie(Function fn[, String message, int status]) Evaluates an expressi ...

  5. java笔试之查找组成一个偶数最接近的两个素数

    任意一个偶数(大于2)都可以由2个素数组成,组成偶数的2个素数有很多种情况,本题目要求输出组成指定偶数的两个素数差值最小的素数对. package test; import java.util.Sca ...

  6. 基于第三方开源库的OPC服务器开发指南(3)——OPC客户端

    本篇将讲解如何编写一个OPC客户端程序测试我们在前文<基于第三方开源库的OPC服务器开发指南(2)——LightOPC的编译及部署>一篇建立的服务器.本指南的目的是熟悉OPC服务器的开发流 ...

  7. 2018-10-8-Win10-使用-GHO-安装出现-UWP-软件打开闪退-应用商店无法安装软件

    title author date CreateTime categories Win10 使用 GHO 安装出现 UWP 软件打开闪退 应用商店无法安装软件 lindexi 2018-10-8 18 ...

  8. 服务启动脚本start_boot.sh

    vim start_boot.sh #!/bin/bash usage(){ echo "$0 [start|stop|usage]" } status_springboot(){ ...

  9. Java迷宫代码,广度优先遍历,最短路径

    使用一个队列,采用层层扩张的方式,寻找迷宫最优的路径信息,再用一个迷宫节点数组记录行走信息方向常量定义: public interface Constant { // 右方向 int RIGHT = ...

  10. 十一. for of

    const fruits = ['Apple','Banana','Orange','Mango']; es5: 可读性差 for(let i=0; i < fruits.length; i + ...