【问题标题】:Issues with importing pylab on Mac OS X 10.8.3在 Mac OS X 10.8.3 上导入 pylab 的问题
【发布时间】:2013-04-18 19:59:44
【问题描述】:

导入 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 存储库并执行以下操作安装 matplotlib 和 numpy:

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

非常感谢您在解决此问题方面的任何帮助。

【问题讨论】:

  • 能否正确格式化回溯?它甚至完整吗?我看不到异常类型。
  • 抱歉,感谢您修复格式,我添加了完整的堆栈跟踪。

标签: python numpy matplotlib osx-mountain-lion


【解决方案1】:

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

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

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

【讨论】:

  • 我想我必须使用开发源;但是我确实是从 Master 分支安装的。
  • 大师好像坏了。下载 tarball,或签出 1.2.1rc1 或 1.2.0。
  • 我采取了简单的方法,直接编辑文件删除'b',它现在可以工作了:)。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    三位一体:

    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
    

    【讨论】:

    • OP 正在使用 master,目前已损坏。不是安装问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 2012-08-15
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 2011-03-05
    相关资源
    最近更新 更多