当我尝试导入时出现ImportError:
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
state = { postArrays: []} // empty array in state to update
let postArrays = []; // the array that needs pushing to state
if (posts) {
postArrays = posts.reduce((acc, obj) => {
if (obj.post_type) {
if (!acc[obj.post_type.social.name]) {
acc[obj.post_type.social.name] = [];
}
acc[obj.post_type.social.name].push({
id: obj.id,
contentType: { value: obj.post_type.id, label: obj.post_type.name },
date: obj.publication_date,
});
}
return acc;
}, []);
if (!this.state.postsLoaded) {
for (let key in postArrays) {
this.setState(
{ postArrays: [key.toLocaleLowerCase()]: postArrays[key] },
this.setState({ postsLoaded: true }),
);
}
}
}
模块似乎出了点问题。
有人可以帮忙弄清楚吗?
答案 0 :(得分:2)
您在那里遇到了依赖混乱的情况。检查堆栈跟踪。请在尝试导入queue
的那一行中看到,并解析为/Users/.../queue.py
。我猜那是你写的一些文件。 python导入机制在queue.py
的{{1}}和queue.py
之间是混乱的。
尝试将concurrent.futures
文件重命名为其他名称。
答案 1 :(得分:0)
您可以共享您的队列文件吗?如果我们从并发导入,它应该可以工作。未来,请在python 3.2或更高版本中导入ThreadPoolExecutor 。如果您可以共享queue.py文件的片段进行更多研究,非常乐意进行调查。尝试更改queue.py的名称,然后运行,如果不起作用,请共享您的代码段,我会为您调查一下。