无法在 python 中导入 Difflib。我该如何解决?
Cannot Import Difflib in python. How can I solve?
我正在尝试使用 difflib,但出现导入错误。有人可以帮忙吗?
这是回溯:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "difflib.py", line 1, in <module>
from difflib import SequenceMatcher
ImportError: cannot import name SequenceMatcher
解决方案是不将源文件命名为 difflib.py
,因为在这种情况下 Python 会采用它而不是实际需要的 difflib
。
(由于问题已在评论中解决且未发布答案,因此受到relevant meta question I'm adding this answer to make the question complete. I'm not trying to get credit for Kevin's or BrenBarn解决方案的启发,我将其发布为社区维基回答。)
我正在尝试使用 difflib,但出现导入错误。有人可以帮忙吗? 这是回溯:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "difflib.py", line 1, in <module>
from difflib import SequenceMatcher
ImportError: cannot import name SequenceMatcher
解决方案是不将源文件命名为 difflib.py
,因为在这种情况下 Python 会采用它而不是实际需要的 difflib
。
(由于问题已在评论中解决且未发布答案,因此受到relevant meta question I'm adding this answer to make the question complete. I'm not trying to get credit for Kevin's or BrenBarn解决方案的启发,我将其发布为社区维基回答。)