(转)[Python]macOSX中使用python matplotlib模块的问题解决

网友投稿 231 2022-11-15

(转)[Python]macOSX中使用python matplotlib模块的问题解决

在mac OSX 上,使用python matplotlib库时,出现问题:

>>> import numpy as np>>> import matplotlib.pyplot as pltTraceback (most recent call last): File "", line 1, in File "/Users/david/anaconda2/envs/tensorflow/lib/python3.6/site-packages/matplotlib/pyplot.py", line 113, in _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/Users/david/anaconda2/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup [backend_name], 0) File "/Users/david/anaconda2/envs/tensorflow/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 19, in from matplotlib.backends import _macosxRuntimeError: 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.

网络上介绍了2中方法, 测试都可以。

方法一:

添加如下两行 代码解决:

>>> import matplotlib>>> matplotlib.use('TkAgg')##在import matplotlib下的模块,如pyplot等之前添加上面2句>>> import matplotlib.pyplot as plt

方法二:

在每个python脚本文件中都这么写,有些别扭。

添加一下matplotlib的配置:

echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:智能交通系统如何加入rfid技术
下一篇:2020有点累。。。
相关文章

 发表评论

暂时没有评论,来抢沙发吧~