[英]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.