从matplotlib导入pyplot时会挂起

时间:2015-09-06 15:15:32

标签: macos python-2.7 matplotlib osx-elcapitan

我正在尝试导入pyplot,但我的python代码无法运行并卡在以下位置:

from matplotlib import pyplot as plt

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "matplotlib/pyplot.py", line 24, in <module>
    import matplotlib.colorbar
  File "matplotlib/colorbar.py", line 29, in <module>
    import matplotlib.collections as collections
  File "matplotlib/collections.py", line 23, in <module>
    import matplotlib.backend_bases as backend_bases
  File "matplotlib/backend_bases.py", line 50, in <module>
    import matplotlib.textpath as textpath
  File "matplotlib/textpath.py", line 11, in <module>
    import matplotlib.font_manager as font_manager
  File "matplotlib/font_manager.py", line 1356, in <module>
    _rebuild()
  File "matplotlib/font_manager.py", line 1341, in _rebuild
    fontManager = FontManager()
  File "matplotlib/font_manager.py", line 989, in __init__
    self.ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "matplotlib/font_manager.py", line 318, in findSystemFonts
    for f in get_fontconfig_fonts(fontext):
  File "matplotlib/font_manager.py", line 275, in get_fontconfig_fonts
    output = pipe.communicate()[0]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 791, in communicate
    stdout = _eintr_retry_call(self.stdout.read)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
    return func(*args)

我尝试使用pip卸载matplotlib,以便我可以重新安装该软件包,但这也会引发一个冗长的错误列表。我在Mac OSX 10.11上运行它。

1 个答案:

答案 0 :(得分:2)

更好地使用Conda。 我也遇到过这个问题[在windows中]。我完全卸载并重新安装了python。然后,它是完美的。我想,这是因为文件损坏了。不过,我搬到了conda环境。它更加光滑舒适。

  1. 从Scipy页面下载Anaconda
  2. 打开Conda命令提示符
  3. 使用代码:-conda install pymc pymc
  4. 此代码安装Conda环境,Scipy,Pymc,Numpy,matplotlib和设置工具
  5. 如果您只想要matplotlib,可以使用pip install matplotlib。
  6. 对我有用。

    如果您想重新使用现有框架,请更好地卸载python安装程序并重新安装。然后尝试pip安装。它运作顺利。

    希望这有帮助。