我正在与numpy和枕头(替代PIL在3.4),但一直有问题的进口枕头。我在这里发现了一个类似的帖子:ImportError: Cannot import name X
然而,这篇文章使用他自己创建的库,问题是他的模块相互导入,创建了循环依赖的导入。
但是,我的代码不使用我自己的模块,下面是代码:
import PIL
from PIL import ImageGrab
import numpy
img = ImageGrab.grab()
imgLoad = img.load()
size = img.size()然后返回错误:
Traceback (most recent call last):
File "E:/Family Documents/Matthew's Documents/Python/PIL.py", line 1, in <module>
import PIL
File "E:/Family Documents/Matthew's Documents/Python\PIL.py", line 2, in <module>
from PIL import ImageGrab
ImportError: cannot import name 'ImageGrab'另一件有趣的事情是,当我第一次安装Pillow ( PIL )时,我在shell中尝试了它,并且"from PIL import ImageGrab“起了作用。
另外,如果我重新启动shell (关闭它并重新打开它),手动输入的命令也可以工作。这表明python出了点问题,因为重新输入"import“会抛出相同的错误消息”无法导入名称'ImageGrab'“。
谢谢你的帮助
发布于 2015-03-27 19:45:33
哈,这个已经咬了我好几次了。
您的跟踪显示了文件名:
E:/Family Documents/Matthew's Documents/Python/PIL.py您的PIL.py是首先找到的,所以您尝试从正在执行的模块中导入名称,而不是从实际安装的库中导入名称。
https://stackoverflow.com/questions/29308936
复制相似问题