Pydev 找不到 matplotlib 模块
我刚刚使用 win32 安装程序在我的 windows 7 Python 2.6.5 计算机 上安装了 matplotlib。我尝试了 matplotlib 网站上的一些示例来测试安装, 在 Idle 下,一切正常,但 Pydev 1.9 (Eclipse 3.6) 无法找到任何子模块。
例如 import matplotlib
不会导致任何错误
,但 from matplotlib.path import Path
会抛出异常
ImportError: No module named path
我已将 matplotlib 路径添加到 eclipse 中的系统 PYTHONPATH,我还有什么需要做的吗?
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您的文件名为
matplotlib.py
。那么为什么这不起作用就很清楚了:当前目录始终位于系统路径前面,并且您的文件将首先被找到。由于它不包含transforms
子模块,因此导入将会失败。import matplotlib
本身可以工作,因为有一个名为matplotlib
的模块 - 您的文件名为matplotlib.py
。只需重命名该文件即可。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 atransforms
submodule, the import will fail.import matplotlib
itself works because there is a module calledmatplotlib
—your file calledmatplotlib.py
. Simply rename the file.