无法导入pylab?

3 投票
2 回答
2226 浏览
提问于 2025-04-16 08:43

我在使用Python 2.6的Snow Leopard上安装了numpy、scipy和matplotlib。可是,当我尝试导入pylab时,好像不太顺利。当我输入'import pylab'时,出现了以下内容:

File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pylab.py", line 216, in <module>
    from matplotlib import mpl  # pulls in most modules
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/mpl.py", line 2, in <module>
    from matplotlib import axis
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axis.py", line 10, in <module>
    import matplotlib.font_manager as font_manager
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py", line 1339, in <module>
    _rebuild()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py", line 1326, in _rebuild
    fontManager = FontManager()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py", line 1004, in __init__
    self.ttffiles = findSystemFonts(paths) + findSystemFonts()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py", line 343, in findSystemFonts
    for f in get_fontconfig_fonts(fontext):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/font_manager.py", line 301, in get_fontconfig_fonts
    output = pipe.communicate()[0]
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 683, in communicate
    stdout = self.stdout.read()

这是怎么回事?pylab是不是需要我没有的东西?它似乎无法读取某些东西,但我不太明白那是什么..

2 个回答

0

尝试一下

from pylab import *

如果你在你的Python环境中成功安装了pylab,就不会出现任何错误。

5

耐心等一下。问题在于,第一次运行fc-list的时候需要花费比较长的时间,所以看起来像是卡住了;但是如果你等2到3分钟,它会完成,然后之后运行就会快很多。

我以管理员身份在命令行中运行了fc-list,这可能初始化了某种缓存;虽然不确定这样做是否必要,但确实有效!

撰写回答