![](/img/trans.png)
[英]Why do I get NameError: name 'as_completed' is not defined (I have from concurrent.futures import ThreadPoolExecutor)
[英]It gives me ImportError when I import `from concurrent.futures import ThreadPoolExecutor`. Does anyone know why?
尝试导入时出现ImportError:
from concurrent.futures import ThreadPoolExecutor
错误:
Traceback (most recent call last):
File "queue.py", line 4, in <module>
from concurrent.futures import ThreadPoolExecutor
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/__init__.py", line 48, in __getattr__
from .thread import ThreadPoolExecutor as te
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 11, in <module>
import queue
File "/Users/tigranfahradyan/Desktop/python3/learning/queue.py", line 4, in <module>
from concurrent.futures import ThreadPoolExecutor
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/__init__.py", line 48, in __getattr__
from .thread import ThreadPoolExecutor as te
ImportError: cannot import name 'ThreadPoolExecutor' from 'concurrent.futures.thread' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py)
queue
模块似乎出了点问题。 谁能帮忙解决这个问题?
您在那里遇到了依赖混乱的情况。 检查堆栈跟踪。 在尝试导入queue
那一行中看到该行,该行解析为/Users/.../queue.py
。 我猜那是你写的一些文件。 蟒蛇进口机制是混淆之间queue.py
和queue.py
的concurrent.futures
。
尝试将您的queue.py
文件重命名为其他名称。
您可以共享您的队列文件吗? 如果我们从并发导入,它应该可以工作.futures在python 3.2或更高版本中导入ThreadPoolExecutor 。 如果您可以共享queue.py文件的片段进行更多研究,非常乐意进行调查。 尝试更改queue.py名称并运行,如果不起作用,请分享您的代码段,我会为您调查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.