Pydev 找不到 matplotlib 模块

发布于 2024-09-14 23:54:44 字数 1562 浏览 2 评论 0原文

我刚刚使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2024-09-21 23:54:45

似乎您的文件名为 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文