我正试图使用OSX10.6上Python2.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
>>>
我做错什么了,我不能像脚本那样导入这些?
对于ImportError:似乎存在架构不匹配。也许您已经安装了32位版本的matplotlib,但正在使用64位Python?下面的shell命令打印什么?
对于AttributeError:您必须明确地导入
matplotlib.pyplot
,它不会在只导入matplotlib
时自动导入。最常见的别名方案是:然后可以使用
plt
名称绘制直方图:我认为最好的选择是使用您拥有的Python。说明here。
相关问题 更多 >
编程相关推荐