在Mac OS X 10.8.3上导入pylab的问题

时间:2013-04-18 19:59:44

标签: python numpy matplotlib osx-mountain-lion

导入pylab时出现以下错误:

Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/pylab.py", line 225, in <module>
    import matplotlib.finance
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/finance.py", line 23, in <module>
    from matplotlib.collections import LineCollection, PolyCollection
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/collections.py", line 23, in <module>
    import matplotlib.backend_bases as backend_bases
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/backend_bases.py", line 50, in <module>
    import matplotlib.textpath as textpath
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/textpath.py", line 11, in <module>
    import matplotlib.font_manager as font_manager
  File "/Library/Python/2.7/site-packages/matplotlib-1.3.x-py2.7-macosx-10.8-intel.egg/matplotlib/font_manager.py", line 1297
    _fc_match_regex = re.compile(rb'\sfile:\s+"([^"]*)"')
                                                       ^
SyntaxError: invalid syntax

使用自制程序安装的依赖项

brew install freetype
brew install libpng

通过克隆github repo安装matplotlib和numpy:

sudo python setup.py build
sudo python setup.py install

非常感谢任何解决此问题的帮助。

3 个答案:

答案 0 :(得分:4)

该文件中存在语法错误。我猜你在使用开发资源?那个rb不应该在正则表达式之前(在Python 2.x中它应该是r,在Python 3.x中可能是b

更新:是的。这是错误的提交:

https://github.com/matplotlib/matplotlib/commit/2415c6200ebdba75a0571d71a4569f18153fff57

答案 1 :(得分:0)

三位一体:

sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy

如果您使用master编译它,请运行sudo brew update然后:

sudo brew install freetype
sudo brew install libpng

然后构建并安装:

sudo python setup.py build
sudo python setup.py install

答案 2 :(得分:0)

应该是br。这将在matplotlib master中修复。