module 'queue' has no attribute 'Queue'解決方法
import queue
q = queue.Queue()
q.put('a')
q.put('b')
print(q.get())
错误:AttributeError: module 'queue' has no attribute 'Queue'
AttributeError: module 'queue' has no attribute 'Queue'
AttributeError: module 'queue' has no attribute 'Queue'
AttributeError: module 'queue' has no attribute 'Queue'
解决方案一:
在Python 2上,模块名为Queue,在Python 3上,模块被重命名以遵循PEP8准则(模块名称均使用小写字母),使其成为队列。该类在所有版本上仍为Queue(PEP8之后)。
通常,编写版本可移植导入的方式是:
try:
import queue
except ImportError:
import Queue as queue
解决方案二:把执行程序命名和包名一样导致错误。
文件命名成了 queue.py 更改为queue1.py就ok了 !
网友评论