解决python在本机Mac上出错:RuntimeError: Python is not installed as a framework.

来源:互联网 发布:弱电设计软件 编辑:程序博客网 时间:2024/05/22 00:48

一. 问题现象: 

调用库:#import matplotlib.pyplot as plt

弹出错误提示:

from matplotlib.backends import _macosx RuntimeError: Python is not installed as a framework. TheMac OS X backend will not be able to function correctly if Pythonis not installed as a framework. See the Python documentation formore 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.
二.问题解决

==================================

2014-01-10 (注) 原方案存在问题:在安装cx_Freeze-4.3.2的时候,无法找到需要的库文件.

在Python3.3的源码包里面,有ReadMe文件,里面有段话:

 31 On Mac OS X, if you have configured Python with --enable-framework, you should
 32 use "make frameworkinstall" to do the installation.  Note that this installs the
 33 Python executable in a place that is not normally on your PATH, you may want to
 34 set up a symlink in /usr/local/bin.

所以,解决办法是:

 ./configure --enable-framework
sudo  make frameworkinstall

sudo make install

==================================


(1) 安装python3.3后,按照如下文章内容操作

http://www.chenwg.com/python/%E6%9B%B4%E6%96%B0mac%E8%87%AA%E5%B8%A6%E7%9A%84python.html

或者

http://blog.richieliu.com/

(2) 删除其他目录下的python

(3)过程中曾经尝试:修改配置文件 matplotlibrc. 

locate该文件并拷贝到~/.matplotlib/ 目录下进行编辑.

但本机仍然失败,因为依赖其他文件(库).

因此决定采用(1)(2)中方案,最终成功.


三. 原因分析和资料索引

(1) 本机上有2个python3.3,一个在/opt下,一个在/usr/bin下. 删除/opt下python结果OK.

猜测:每次调用都是跑到/opt下的python,导致出错.

rm -rf /opt/local/Library/Frameworks/Python.framework/

(2) 正确的python运行目录

/System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3

(3) matplot运行(傅里叶变换)所需库文件列表:

Python-3.3.3
FFT-tools
lxml-3.2.4
matplotlib-1.3.1
nose-1.3.0
numpy-1.8.0
pyparsing-2.0.1
python-dateutil-2.1
setuptools-1.4
six-1.4.1
tornado-3.1.1