繁体   English   中英

Python-无法导入名称-3.4

[英]Python - Cannot import name - 3.4

我正在使用numpy和Pillow(在3.4中替换了PIL),但是在导入Pillow时遇到了问题。 我在这里找到了类似的帖子: ImportError:无法导入名称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)时,我在外壳中进行了尝试,并且“从PIL导入ImageGrab”起作用了。

另外,如果我重新启动外壳程序(将其关闭并重新打开),则手动键入的命令也可以正常工作。 这对我来说暗示着python出现了一些错误,因为重新键入“ import PIL”会引发相同的错误消息“ cannot import name'ImageGrab'”。

谢谢你的帮助

哈,这已经多次咬我了。

您的回溯显示文件名:

E:/Family Documents/Matthew's Documents/Python/PIL.py

PIL.py找到您的PIL.py ,因此您尝试从刚刚执行的模块中导入名称,而不是从已安装的实际库中导入名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM