Python3在virtualenv环境下使用matplotlib绘图遇到的问题

在virtualenv环境下使用matplotlib绘图时遇到了这样的问题:
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.

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

按以下步骤解决:
1. pip 安装 matplotlib后会生成目录 ~/.matplotlib.
2. 在此目录下创建一个文件( ~/.matplotlib/matplotlibrc):matplotlibrc,内容为:backend: TkAgg

保存退出,重新运行即可

猜你喜欢

转载自blog.csdn.net/ocean20/article/details/79322037