简体   繁体   English

当我从并发导入时,它给了我ImportError.futures import ThreadPoolExecutor`。 有人知道为什么吗?

[英]It gives me ImportError when I import `from concurrent.futures import ThreadPoolExecutor`. Does anyone know why?

I get ImportError when I try to import: 尝试导入时出现ImportError:

from concurrent.futures import ThreadPoolExecutor

ERROR: 错误:

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)

It seems that something is wrong with queue module. queue模块似乎出了点问题。 Can anyone help to figure this out? 谁能帮忙解决这个问题?

You've got a case of dependency confusion there. 您在那里遇到了依赖混乱的情况。 Check the stack-trace. 检查堆栈跟踪。 See that line where it's trying to import queue and that resolves to /Users/.../queue.py . 在尝试导入queue那一行中看到该行,该行解析为/Users/.../queue.py I'm guessing that's some file you wrote. 我猜那是你写的一些文件。 The python import mechanism is confused between that queue.py and the queue.py of concurrent.futures . 蟒蛇进口机制是混淆之间queue.pyqueue.pyconcurrent.futures

Try renaming your queue.py file to something else. 尝试将您的queue.py文件重命名为其他名称。

Can you share your Queue file. 您可以共享您的队列文件吗? It should work if we import from concurrent.futures import ThreadPoolExecutor in python 3.2 or later version. 如果我们从并发导入,它应该可以工作.futures在python 3.2或更高版本中导入ThreadPoolExecutor It would be very happy to look into it if you could share snippet of queue.py file to investigate more. 如果您可以共享queue.py文件的片段进行更多研究,非常乐意进行调查。 Try changing queue.py name and run, if not works, share your snippet, i will look into into for you. 尝试更改queue.py名称并运行,如果不起作用,请分享您的代码段,我会为您调查。

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

相关问题 为什么我得到 NameError: name 'as_completed' is not defined (我有 from concurrent.futures import ThreadPoolExecutor) - Why do I get NameError: name 'as_completed' is not defined (I have from concurrent.futures import ThreadPoolExecutor) Python concurrent.futures 试图导入函数 - Python concurrent.futures trying to import functions 从concurrent.futures使用ThreadPoolExecutor时的max_workers数量? - Number of max_workers when using ThreadPoolExecutor from concurrent.futures? parallel.futures ThreadPoolExecutor无法等待吗? - concurrent.futures ThreadPoolExecutor fails to wait? python中concurrent.futures ThreadPoolExecutor的问题 - Problem with concurrent.futures ThreadPoolExecutor in python Python concurrent.futures threadpoolexecutor 线程管理 - Python concurrent.futures threadpoolexecutor thread management Python ThreadPoolExecutor (concurrent.futures) 内存泄漏 - Python ThreadPoolExecutor (concurrent.futures) memory leak 使用 Tkinter 和 Concurrent.Futures / ThreadPoolExecutor Class - Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class 导入错误:无法从“concurrent.futures.process”导入名称“ProcessPoolExecutor” - ImportError: cannot import name 'ProcessPoolExecutor' from 'concurrent.futures.process' Python 3 concurrent.futures:如何将失败的期货添加回ThreadPoolExecutor? - Python 3 concurrent.futures: How to add back failed futures to ThreadPoolExecutor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM