开发者

Pydev can't find matplotlib modules

开发者 https://www.devze.com 2023-01-12 02:54 出处:网络
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,

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 m开发者_如何学编程atplotlib 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消