1

导入 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

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

4

3 回答 3

4

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

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

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

于 2013-04-18T20:18:58.403 回答
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
于 2013-04-18T20:25:47.197 回答
0

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

于 2013-04-18T22:26:44.493 回答