在 Mac OSX 10.6 上的 python 2.7 中导入 matplotlib.mlab 和 .pyplot 时出现问题

2023-12-10

我正在尝试在 OSX 10.6 上的 Python 2.7 中使用 matplotlib 绘制直方图

我已经验证可以将 numpy、scipy 和 matplotlib 导入到 python 中。 matplotlib 网站上的示例脚本可以

#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

但是,我在执行此操作时遇到错误。这是我尝试导入 mlab 时发生的情况。

Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.mlab as mlab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mlab.py", line 151, in <module>
    import matplotlib.nxutils as nxutils
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/nxutils.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/nxutils.so: no matching architecture in universal wrapper
>>> 

我做错了什么,无法像脚本那样导入这些内容?


For the 导入错误: 似乎存在架构不匹配。也许您已经安装了 32 位版本的 matplotlib,但使用的是 64 位 Python?以下 shell 命令打印什么?

file /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/nxutils.so

For the 属性错误:您必须显式导入matplotlib.pyplot,刚导入时不会自动导入matplotlib。最常见的别名方案是:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

然后你可以使用以下命令绘制直方图plt name:

plt.hist(...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Mac OSX 10.6 上的 python 2.7 中导入 matplotlib.mlab 和 .pyplot 时出现问题 的相关文章

随机推荐