简体   繁体   English

Python错误:AttributeError:'模块'对象没有属性'heappush'

[英]Python error : AttributeError: 'module' object has no attribute 'heappush'

I am trying some simple programs which involve multiprocessing features in Python. 我正在尝试一些简单的程序,这些程序涉及Python中的多处理功能。

The code is given below: 代码如下:

from multiprocessing import Process, Queue

def print_square(i):
  print i*i

if __name__ == '__main__':
  output = Queue()
  processes = [Process(target=print_square,args=(i,)) for i in range(5)]

  for p in processes:
    p.start()

  for p in processes:
    p.join()

However, this gives an error message AttributeError: 'module' object has no attribute 'heappush'. 但是,这会给出一条错误消息AttributeError: 'module' object has no attribute 'heappush'. The complete output upon executing the script is given below: 执行脚本后的完整输出如下:

Traceback (most recent call last):
  File "parallel_3.py", line 15, in 
    output = Queue()
  File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\__init__.py", line 217, in Queue
    from multiprocessing.queues import Queue
  File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\queues.py", line 45, in 
    from Queue import Empty, Full
  File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 212, in 
    class PriorityQueue(Queue):
  File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 224, in PriorityQueue
    def _put(self, item, heappush=heapq.heappush):
AttributeError: 'module' object has no attribute 'heappush'

The code compiles fine if the output=Queue() statement is commented. 如果对output = Queue()语句进行注释,则代码可以正常编译。 What could be possibly causing this error ? 是什么可能导致此错误?

Your filename should be the package name. 您的文件名应为程序包名称。 Change to another filename such as heap and it will work. 更改为另一个文件名,例如heap ,它将起作用。

暂无
暂无

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

相关问题 Python错误:AttributeError:'module'对象没有属性 - Python error: AttributeError: 'module' object has no attribute Jython:子流程模块错误,AttributeError:'module'对象没有属性'python' - Jython: Error in subprocess module, AttributeError: 'module' object has no attribute 'python' Python Pandas错误:AttributeError:“模块”对象没有属性“格式” - Python Pandas Error: AttributeError: 'module' object has no attribute 'formats' Python 2.7错误:“ AttributeError:'模块'对象没有属性'Unit'” - Python 2.7 error: “AttributeError: 'module' object has no attribute 'Unit'” AttributeError:'module'对象没有属性'subscribe'Python - AttributeError: 'module' object has no attribute 'subscribe' Python AttributeError:'module'对象没有属性'call':Python - AttributeError:'module' object has no attribute 'call' :Python Python-> AttributeError:“模块”对象没有属性“主” - Python -> AttributeError: 'module' object has no attribute 'main' python AttributeError:“模块”对象没有属性“ monthcalendar” - python AttributeError: 'module' object has no attribute 'monthcalendar' python 属性错误:“模块”object 没有属性“fft” - python attributeerror: 'module' object has no attribute 'fft' Python:AttributeError:'module'对象没有属性'socketpair' - Python: AttributeError: 'module' object has no attribute 'socketpair'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM