Python在Mac上报错:RuntimeError: Python is not installed as a framework.解决办法

在mac上使用virtualenv虚拟机,import matplotlib或者import seaborn时报错:

  • 解决方法:

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.

 在虚拟机中或者命令行状态下输入:

 vim ~/.matplotlib/matplotlibrc

 创建一个名为matplotlib的文件,按i 进入编辑模式,输入

 backend: TkAgg

 按esc退出编辑模式,输入 :wq   保存并退出,重启终端进入python即可。

  • 如果遇到以下提示:E212:Can't open file for writing

则需要管理员权限使用vim,输入

 sudo vim ~/.matplotlib/matplotlibrc

然后按照以上步骤编辑文件,按esc退出编辑模式,输入 :wq! 保存并退出编辑模式,重启命令行即可。

你可能感兴趣的:(Python在Mac上报错:RuntimeError: Python is not installed as a framework.解决办法)