`

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

阅读更多

转自:https://blog.csdn.net/whereismatrix/article/details/78195783

 

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

>>> import numpy as np
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/david/anaconda2/envs/tensorflow/lib/python3.6/site-packages/matplotlib/pyplot.py", line 113, in <module>
    _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 <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 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

 

分享到:
评论

相关推荐

    详解pyenv下使用python matplotlib模块的问题解决

    ### 详解pyenv环境下使用Python Matplotlib模块的问题解决 #### 背景介绍 在使用Python进行数据分析或可视化处理时,经常会用到Matplotlib库。然而,在特定的开发环境中(如使用pyenv管理Python版本的情况下),...

    Python库 | matplotlib-3.5.0b1-cp38-cp38-macosx_10_9_x86_64.whl

    资源分类:Python库 所属语言:Python 资源全名:matplotlib-3.5.0b1-cp38-cp38-macosx_10_9_x86_64.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl

    matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl matplotlib-3.9.2-cp39-cp39-macosx_11_0_arm64.whl ...

    Matplotlib参考手册.pdf

    Matplotlib是一款流行的Python绘图库,它提供了一个强大的绘图工具,使得数据可视化变得简单而直观。...通过这份手册,用户可以方便地找到解决特定问题的方法,或者了解如何参与到Matplotlib的开发中来。

    matplotlib-3.1.3-cp37-cp37m-macosx_10_9_x86_64.whl

    Python matplotlib包 pip install matplotlib-3.1.3-cp37-cp37m-macosx_10_9_x86_64.whl

    Python库 | kiwisolver-1.3.2-cp39-cp39-macosx_11_0_arm64.whl

    在matplotlib中,kiwisolver用于解决复杂的图形布局问题,如调整轴、图例、文字和其他元素的位置,以确保它们在图表中的相互关系得到正确处理,尤其是在创建交互式或动态图表时。 **安装与使用** kiwisolver的安装...

    matplotlib-2.0.0.tar.gz

    `matplotlib` 是 Python 编程语言中最著名的数据可视化库之一,它提供了丰富的图形绘制功能,用于创建静态、动态、交互式的数据可视化图表。这个压缩包很可能包含了 `matplotlib` 的源代码、文档、示例和其他资源。 ...

    Python库 | PyMCubes-0.0.12-cp37-cp37m-macosx_10_9_x86_64.whl

    安装完成后,用户可以直接在Python环境中导入并使用PyMCubes的功能。 **总结** PyMCubes是一个强大的Python库,为处理三维数据和执行概率编程提供了便利。无论是对于科学研究、数据建模还是机器学习项目,PyMCubes...

    matplotlib-3.9.0rc2-cp311-cp311-macosx_11_0_arm64.whl

    matplotlib-3.9.0rc2-cp311-cp311-macosx_11_0_arm64.whl matplotlib-3.9.0rc2-cp311-cp311-macosx_11_0_arm64.whl matplotlib-3.9.0rc2-cp311-cp311-macosx_11_0_arm64.whl matplotlib-3.9.0rc2-cp311-cp311-macosx...

    Python库 | eqlib-0.25.2-cp36-cp36m-macosx_10_13_x86_64.whl

    Python库是Python编程中不可或缺的一部分,它们提供了丰富的功能和模块,极大地扩展了Python语言的使用范围。本资源是一个名为“eqlib”的Python库的特定版本——0.25.2,专为Python 3.6编译,并针对macOS 10.13及...

    Python库 | ecmwflibs-0.3.5-cp39-cp39-macosx_10_14_x86_64.whl

    要安装`ecmwflibs`,用户需要在命令行环境中使用`pip` 工具,输入以下命令: ``` pip install ecmwflibs-0.3.5-cp39-cp39-macosx_10_14_x86_64.whl ``` 安装完成后,开发者可以在Python脚本中导入并使用该库,例如...

    Python库 | python_rtspm-0.1.8-cp39-cp39-macosx_10_15_x86_64.whl

    在Python开发中,这类库通常会依赖其他Python库,如NumPy用于数值计算,SciPy用于科学计算,Pandas用于数据处理,Matplotlib或Seaborn用于数据可视化。如果“python_rtspm”确实涉及到实时信号处理,那么它可能还...

    黑马2017Python课程配套笔记

    在这段内容中,首先介绍了Python这门编程语言的发展历史。Python语言由Guido van Rossum创造,作为荷兰人,他参与了这门语言的设计和实现。Python语言因其简洁、清晰和易读性而备受推崇,广泛用于多种应用开发中。它...

    Python库 | gogo-1.0.0.macosx-10.6-intel.exe

    这个库可能包含了一系列用于特定功能的Python模块,方便开发者在他们的项目中快速实现特定功能。 Python库是Python编程中的重要组成部分,它们是由预编写好的代码组成,可以被其他Python程序调用。这些库通常包含了...

    Python库 | dtw_python-1.1.3-cp37-cp37m-macosx_10_9_x86_64.whl

    标题中的"dtw_python-1.1.3-cp37-cp37m-macosx_10_9_x86_64.whl"指的是一个Python库的发行版本,名为`dtw_python`,版本号为1.1.3。这个文件是专门为Python 3.7编译的(标记为`cp37`),并且是针对macOS 10.9及更高...

    pycharm使用matplotlib.pyplot不显示图形的解决方法

    4. 解决上述问题之后,后续的代码块(如示例中使用pandas读取csv文件并绘制散点图的代码)应该能够正常工作,调用plt.show()将打开一个图形窗口显示绘制的图像,而不再出现图形界面不显示的问题。 5. 最后,根据...

    matplotlib-3.9.2-cp312-cp312-macosx_10_12_x86_64.whl

    matplotlib-3.9.2-cp312-cp312-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp312-cp312-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp312-cp312-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp312-cp312-macosx_10_12...

    Python库 | NEURON-7.8.0.119-cp35-cp35m-macosx_10_9_intel.whl

    在科学计算和数据分析领域,Python有诸如NumPy、Pandas和Matplotlib等强大的库。NEURON与Python的结合,使神经科学家和计算神经生物学家能够利用Python的强大功能进行神经网络建模。 **NEURON库的主要特性** 1. **...

    matplotlib-3.9.2-cp311-cp311-macosx_10_12_x86_64.whl

    matplotlib-3.9.2-cp311-cp311-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp311-cp311-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp311-cp311-macosx_10_12_x86_64.whl matplotlib-3.9.2-cp311-cp311-macosx_10_12...

Global site tag (gtag.js) - Google Analytics