$pip install numpy然後想測試時,發生如下的import error
$pip install matplotlib
$ python找不到ma模組,找了一下後發現改位置了
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/pyplot.py", line 6, in
from matplotlib.figure import Figure, figaspect
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/figure.py", line 10, in
from axes import Axes, Subplot, PolarSubplot, PolarAxes
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/axes.py", line 6, in
import matplotlib.numerix.npyma as ma
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/__init__.py", line 166, in
__import__('ma', g, l)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/numerix/ma/__init__.py", line 16, in
from numpy.core.ma import *
ImportError: No module named ma
>>> import numpy因此去修改下列檔案
>>> print numpy.__version__
1.5.1
>>> print numpy.core.ma
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ma'
>>> print numpy.ma
>>> quit()
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py裡面有import numpy.core.ma的都改一下
$ vim /Library/Frameworks/Python.framework/Versions/Current/lib/python2.6/site-packages/matplotlib/numerix/npyma/__init__.py
try:最後就可以成功了
from numpy.core.ma import *
except ImportError:
from numpy.ma import *
$ python
Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/matplotlib/__init__.py:62: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5, os, re, shutil, sys, warnings
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
from sets import Set
>>> plt.plot([1,2,3,4])
[]
>>> plt.ylabe('some numbers')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'ylabe'
>>> plt.ylabel('some numbers')
>>> plt.show()
Happy hacks ; )