You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python生成词云报错:No module named 'ImageDraw' 求助

解决Python中导入ImageDraw报错的问题

嘿,这个问题我碰到过好多次啦!你出现No module named 'ImageDraw'错误的核心原因是导入方式不对——ImageDraw是PIL(现在主流用的是它的活跃分支Pillow)库的子模块,不能直接单独import,必须从PIL包里导入才行。

具体修正步骤:

  1. 确认Pillow库是否正确安装
    你提到已经装了pip,但可能还没安装Pillow(现在Python环境里都是用Pillow替代老旧的PIL)。打开命令提示符运行:

    pip install pillow
    

    如果已经安装过,会提示已是最新版本,直接跳过这一步就行。

  2. 修改导入代码
    你原来的代码:

    from PIL import Image
    import ImageDraw
    

    要改成以下两种正确方式之一:

    • 方式一:一次性导入所需模块
      from PIL import Image, ImageDraw
      img_grey = Image.new("L", (10, 15))
      draw = ImageDraw.Draw(img_grey)
      
    • 方式二:分开从PIL导入模块
      from PIL import Image
      from PIL import ImageDraw
      img_grey = Image.new("L", (10, 15))
      draw = ImageDraw.Draw(img_grey)
      

这样调整后,Python就能正确定位到ImageDraw模块,代码就能正常运行啦。

内容的提问来源于stack exchange,提问作者NMB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:09:06