views:

101

answers:

1

I just installed matplotlib on my windows 7 Python 2.6.5 machine with the win32 installer . I've tried some examples from the matplotlib site to test the installation, under Idle everthing works fine but Pydev 1.9 (Eclipse 3.6) cant find any of the sub modules.

e.g import matplotlib doesn't cause any errors

but from matplotlib.path import Path throws

ImportError: No module named path

Ive added the matplotlib path to the system PYTHONPATH in eclipse, is there anything else I need to do?

from pylab import *
import numpy as np
from matplotlib.transforms import Bbox
from matplotlib.path import Path
from matplotlib.patches import Rectangle

rect = Rectangle((-1, -1), 2, 2, facecolor="#aaaaaa")
gca().add_patch(rect)
bbox = Bbox.from_bounds(-1, -1, 2, 2)

for i in range(12):
    vertices = (np.random.random((4, 2)) - 0.5) * 6.0
    vertices = np.ma.masked_array(vertices, [[False, False], [True, True], [False, False], [False, False]])
    path = Path(vertices)
    if path.intersects_bbox(bbox):
        color = 'r'
    else:
        color = 'b'
    plot(vertices[:,0], vertices[:,1], color=color)

show()

Traceback (most recent call last):
  File "I:\My Documents\Programming\Python\Eclipse Projects\test\src\matplotlib.py", line 1, in <module>
    from pylab import *
  File "C:\Python26\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "I:\My Documents\Programming\Python\Eclipse Projects\test\src\matplotlib.py", line 3, in <module>
    from matplotlib.transforms import Bbox
ImportError: No module named transforms
+4  A: 

Seems that your file is called matplotlib.py. Then it's clear why this doesn't work: The current directory is always prepended to the system path, and your file will be found first. Since it doesn't contain a transforms submodule, the import will fail. import matplotlib itself works because there is a module called matplotlib—your file called matplotlib.py. Simply rename the file.

Philipp
OMG how stupid... I ment to call it matplotlib_test.py Thanks!
volting